-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp030.java
More file actions
30 lines (24 loc) · 755 Bytes
/
p030.java
File metadata and controls
30 lines (24 loc) · 755 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
package level02;
import org.junit.Test;
import lib.EulerTest;
public class p030 extends EulerTest {
final int N = 5;
final int L = 1000000;
/**
* Find the sum of all numbers > 1 that equal the sum of Nth powers of their digits.
* <p>
* Since 9^5 < 60000, it is impossible for the sum of the 5th powers of a 7+ digit number to be
* larger than 7x9^5 < 999999. Therefore, only numbers with up to 6 digits need to be checked.
*/
@Test
public void test() {
for (int i : range(2, L)) {
int sumNthPowers = 0;
for (int d : digits(i))
sumNthPowers += pow(d, N);
if (sumNthPowers == i)
ans += i;
}
check(443839);
}
}