- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
Latest commit
27 lines (19 loc) · 540 Bytes
/
Copy pathMain.java
File metadata and controls
27 lines (19 loc) · 540 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
importjava.math.BigInteger;
/*
@author: mc-es
Problem 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?
Answer: 1366
*/
publicclassMain {
publicstaticvoidmain(String[] args) {
BigIntegernumber = newBigInteger("2").pow(1000);
StringnumberStr = number.toString();
intsum = 0;
for (inti = 0; i < numberStr.length(); i++) {
sum += Character.getNumericValue(numberStr.charAt(i));
}
System.out.println(sum);
}
}