Code: Select all
5^19 = 5^(20-1) = (5^20)/5
5^20 = (5^4)^5
Therefore 5^19 = [(5^4)^5]/5
Done using the pow function in C, that would only require 9 multiplications and a divide by 5, as opposed to 19 multiplications to get the figure originally. Obviously, this isn't a great speed up, but with larger exponents it could be. And at the end of the day, this was just a bit of fun to me.
If a number is prime, you just raise to the next non-prime exponent (add one ) and remember to divide by five at the end...
Are there any quick ways to find two numbers that will come reasonably close (+ or - a few) to the desired exponent?
Maybe some kind of LCM method would be good, but then you're adding divisions and arrays and things...
-Mole