I'm trying to solve Project Euler #16:
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^1000?
question looks simple but Instead of using modulus 10 I tried to solve the question like this:
public class Main {
public static void main(String[] args) {
long number = (long) Math.pow(2,100);
long sum=0;
String number2 = String.valueOf(number);
char[] digits = number2.toCharArray();
for (char digit : digits) {
sum = sum + digit;
}
System.out.println(sum);
}
}
However it gives a wrong answer, I can't see my mistake, Isn't it possible to solve this question with this way?