-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Problem30.java
38 lines (31 loc) · 882 Bytes
/
Problem30.java
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
36
37
38
/*
* File: Problem30.java
* ----------------------
* Finds the sum of all numbers that can be written
* as the sum of fifth powers of the digits.
*/
public class Problem30 {
public static void main (String[] args) {
// to calculate runtime of different methods
double startTime = System.nanoTime();
int solution = 0;
int number = 2;
// This number was just a guess. Added requested power's worth of 0s to 2
while (number < 200000) {
int working = number;
int total = 0;
while (working / 10.0 > 0) {
int powered = (int)Math.pow(working % 10, 5);
total += powered;
working /= 10;
}
if (total == number) {
solution += number;
}
number++;
}
System.out.println(solution);
double duration = (System.nanoTime() - startTime) / 1000000000;
System.out.println(duration + " seconds");
}
}