Once you figure out the actual amount of oil in your 24:1 mixture, you can easily figure out how much total gasoline you need, and then figure out how much gasoline you should add.
Let's talk in volumes.
24:1 is 1/25 oil, 24/25 gasoline (at least in my head). Likewise, 40:1 is 1/41 oil 40/41 gasoline.
We can use a little algebra to set up some equations for the individual liquids (gas, then oil).
40/41 * (Total Liquid) = 24/25 * (1 Gallon) + 1 * (Amount gasoline to add)
1/41 * (Total Liquid) = 1/25 * (1 Gallon)
Since you aren't adding any oil, this is pretty simple. You can use either equation to determine how much gasoline to add (if you were combining two mixes, it'd be more interesting, as you would have to substitute equations).
The second equation is pretty simple (as the Total Liquid = 1 gallon + how much you add)
41/25 = 1.64 Gallons (total), meaning, you add 0.64 Gallons of gasoline for every gallon of mixture you have.
The other equation can be arranged for the same result.
40/41 + 40/41 * gas added = 24/25 + 1*gas added
gas added = 40 - (41*24)/25 = 0.64 gallons
I hope I didn't make this too confusing