I'm working on Project Euler, writing solutions in JavaScript. However, it seems Problem 16 cannot be solved with Javascript:
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 21000?
Because JavaScript's 64bit precision isn't big enough to hold the number, calculating Math.pow(2, 1000)
gives 1.0715086071862673e+301
. Obviously, I can't use this value to solve the problem because it doesn't contain all the digits of 21000.
Is there another way to solve this problem? Note that I am not asking how to get around the precision issue; however, if that's the only solution, so be it.
Ideally, I'd like to find an alternate solution (maybe a super-epic math approach?) to the problem.
(as an side note, i'm not trying to cheat and wean the answer out of SO. I've solved it, but I had to use Python)