-
Notifications
You must be signed in to change notification settings - Fork 1
/
Problem026_ReciprocalCycles.java
61 lines (47 loc) · 1.63 KB
/
Problem026_ReciprocalCycles.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.util.ArrayList;
/**
* Created by Sneeuwpopsneeuw on 11-Aug-16.
*/
public class Problem026_ReciprocalCycles {
public static void main(String[] args) {
int ansValue = 0, ansI = 0, tmp = 0;
for (int i=2; i < 1000; i++) {
if( (1000D % i == 0) == false ) { // 0,5 0.25 .... excluded
if( (i % 16 == 0) == false ) { // /16 /32 /64 excluded
if( (i % 10 == 0) == false ) { // the recurring cycle of 6 = 60
System.out.println(i + " : " + 1D / (double) i); // prints 7 : 0.14285714285714285
tmp = damn( i );
if (tmp > ansValue) {
ansValue = tmp;
ansI = i;
}
System.out.println( " "+tmp );
}
}
}
}
System.out.println("ansValue = "+ansValue+" ansI = "+ansI);
}
private static int damn(int x) {
ArrayList<Integer> map = new ArrayList<>();
String text = "";
int value = 1, subtraction = 0;
boolean firstTime = false;
for (int i=1; i < 999_999; i++) {
if (value / x > 1) {
if (firstTime) {
subtraction = i;
firstTime = false;
}
if (map.contains(value))
return i - subtraction;
map.add(value);
value = value % x; // keep remainder
}
value *= 10; // shift
}
return 1;
}
}
/*
*/