-
Notifications
You must be signed in to change notification settings - Fork 0
/
RecurringCycle.java
53 lines (46 loc) · 988 Bytes
/
RecurringCycle.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
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class RecurringCycle {
public static void main(String[] args)
{
int max = 0;
for (int k = 1; k <1000; k++)
if (rec(k)>max)
max = k;
System.out.println(max);
}
public static int rec(int n){
int k = 1;
int r = 0;
int count = 0;
Map<Integer, ArrayList<Integer>> m = new HashMap<Integer, ArrayList<Integer>>();
while (true)
{ while (k/n==0)
k = k*10;
//System.out.println(k);
if (k%n == 0)
break;
else{
r = k/n;
k = k%n;
// System.out.println(r+ " " +k);
if (!m.containsKey(r))
{m.put(r, new ArrayList<Integer>());
m.get(r).add(k);
}
else if (m.containsKey(r)){
if(m.get(r).contains(k)){
for (int i = 1; i<10;i++){
if(m.containsKey(i))
count+=m.get(i).size();}
return count;
}
else{m.get(r).add(k); count++;}
}
}
}
return -1;
}
}