-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem26.java
38 lines (31 loc) · 1.07 KB
/
Problem26.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
package com.prog.ProjectEulerPrograms;
public class Problem26 {
public static void main(String[] args) {
int sequenceLength = 0;
int num = 0;
// execution start time
long start = System.currentTimeMillis();
for (int i = 1000; i > 1; i--) {
if (sequenceLength >= i) {
break;
}
int[] foundRemainders = new int[i];
int value = 1;
int position = 0;
while (foundRemainders[value] == 0 && value != 0) {
foundRemainders[value] = position;
value *= 10;
value %= i;
position++;
}
if (position - foundRemainders[value] > sequenceLength) {
num = i;
sequenceLength = position - foundRemainders[value];
}
}
// execution end time
long end = System.currentTimeMillis();
System.out.println("Value of d is: "+num);
System.out.println("Execution time in milliseconds: "+(end - start)+" ms");
}
}