-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEulerProblem0026.java
More file actions
32 lines (29 loc) · 917 Bytes
/
EulerProblem0026.java
File metadata and controls
32 lines (29 loc) · 917 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
import java.math.BigDecimal;
import java.util.Vector;
public static void main(String[] args) {
int i, currentDividend, len;
BigDecimal bigI;
int maxLen = 1;
int maxD = 3;
Vector<Integer> remainders;
for (i = 3; i < 1000; i++) {
bigI = BigDecimal.valueOf(i);
try {
bigI = (BigDecimal.ONE).divide(bigI);
} catch (ArithmeticException ae) {
remainders = new Vector<>();
remainders.add(1);
currentDividend = 10;
while (!remainders.contains(currentDividend%i)) {
remainders.add(currentDividend%i);
currentDividend = 10*(currentDividend%i);
}
len = remainders.size() - remainders.indexOf(currentDividend%i);
if (len > maxLen) {
maxLen = len;
maxD = i;
}
}
}
System.out.println(maxD);
}