-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP10183.java
44 lines (38 loc) · 1.08 KB
/
P10183.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
import java.io.*;
import java.math.BigInteger;
public class P10183 {
private static BigInteger[] cache = new BigInteger[5001];
private static int maxFib = 1;
private static BigInteger fib(int n) {
while(maxFib < n) {
cache[maxFib+1] = cache[maxFib].add(cache[maxFib-1]);
++maxFib;
}
return cache[n];
}
public static void main(String[] args) throws Exception {
cache[0] = BigInteger.ONE;
cache[1] = BigInteger.ONE;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String l;
while((l = br.readLine()) != null) {
BigInteger a = new BigInteger(l.trim().split("\\s+")[0]);
BigInteger b = new BigInteger(l.trim().split("\\s+")[1]);
if(a.equals(BigInteger.ZERO) && b.equals(BigInteger.ZERO))
return;
int idxA = 1;
while(fib(idxA).compareTo(a) != 1)
++idxA;
--idxA;
int idxB = idxA;
while(fib(idxB).compareTo(b) != 1)
++idxB;
--idxB;
int ret = idxB-idxA+1;
if(!fib(idxA).equals(a))
--ret;
System.out.println(ret);
//System.err.println(fib(n).toString().length());
}
}
}