- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
Latest commit
35 lines (26 loc) · 810 Bytes
/
Copy pathMain.java
File metadata and controls
35 lines (26 loc) · 810 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
28
29
30
31
32
33
34
35
/*
@author: mc-es
Problem 48
The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.
Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.
Answer: 9110846700
*/
publicclassMain {
publicstaticvoidmain(String[] args) {
intn = 1000;
Stringlast10Digits = findLastTenDigits(n);
System.out.println("Last ten digits: " + last10Digits);
}
publicstaticStringfindLastTenDigits(intn) {
longmod = 10_000_000_000L;
longselfPowersSum = 0;
for (inti = 1; i <= n; i++) {
longcurrentPower = 1;
for (intj = 1; j <= i; j++) {
currentPower = (currentPower * i) % mod;
}
selfPowersSum = (selfPowersSum + currentPower) % mod;
}
returnString.format("%010d", selfPowersSum);
}
}