A-how Many fibs?
crawling in process ...
crawling failed
Time Limit:1000MS
Memory Limit:32768KB
64bit IO Format:%I64D &%i64u
Description We define the Fibonacci sequence as follows: F1=1 f2=2 f (n) =f (n-1) +f (n-2) (n>=3) Now, given two numbers a and B, calculate how many Fibonacci numbers are between A and B (including boundaries).
Input input contains multiple sets of test data, each set of test data is two nonnegative integers a and B, and when a and B are equal to 0 o'clock, the program ends. 0<=A<=B<=10^100, note that both A and b do not show a leading 0 (that is, the first 0).
Output
The number of outputs between A and B (satisfying the number of a<=f (i) <=b).
Sample Input 10 100 1234567890 9876543210 0 0
Sample Output 5 4
This kind of problem uses the traditional high precision too time-consuming, direct Java
Import
java.io.*;
Import java.math.biginteger;
Import java.util.*;
Public Classmain {
public static void Main (string[] args) {
Scanner cin=newscanner (system.in);
BigInteger A[]=new biginteger[10500];
A[1]=biginteger.one;
A[2]=biginteger.valueof (2);
for (int i=3; i<10500; i++)
A[i]=a[i-1].add (a[i-2);
int sum;
while (Cin.hasnextbiginteger ()) {
Sum=0
BigInteger X=cin.nextbiginteger ();
BigInteger Y=cin.nextbiginteger ();
if (x.equals (Biginteger.zero) &&y.equals (Biginteger.zero))
break;
for (int i=1;i<10500; i++) {
if (A[i].compareto (x) >=0&&a[i].compareto (y) <=0)
sum++;
}
System.out.println (sum);
}
}
}