-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution26.java
More file actions
32 lines (30 loc) · 817 Bytes
/
Copy pathSolution26.java
File metadata and controls
32 lines (30 loc) · 817 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.util.Map;
import java.util.HashMap;
public class Solution26{
static int checkCycle(int d){
Map<Integer,Integer> digitPos = new HashMap<Integer,Integer>();
int mod = 1;
int index = 1;
while(true){
if(digitPos.containsKey(mod)){
return index - digitPos.get(mod);
}
else{
digitPos.put(mod,index);
mod = mod * 10 % d;
index++;
}
}
}
public static void main(String[] args) {
int maxCycle = 0;
int denom = 0;
for(int i = 2; i < 1000; i++){
if(checkCycle(i) > maxCycle){
maxCycle = checkCycle(i);
denom = i;
}
}
System.out.println(denom);
}
}