http://acm.hdu.edu.cn/showproblem.php?pid=1316

大数,斐波那契数列

View Code
import java.io.*;
import java.math.*;
import java.util.*;
import java.text.*;
public class Main
{
    public static void main(String[]args)
    {
        Scanner cin=new Scanner (new BufferedInputStream(System.in));
        BigInteger a,b;
        BigInteger fiba,fibb;
        while(cin.hasNext())
        {
            a=cin.nextBigInteger();
            b=cin.nextBigInteger();
            if(a.equals(BigInteger.valueOf(0)) && b.equals(BigInteger.valueOf(0)))
                break;
            int ans=0;
            fiba=BigInteger.valueOf(1);
            fibb=BigInteger.valueOf(2);
            while(true)
            {
                if(fiba.compareTo(a)>=0 && fiba.compareTo(b)<=0)ans++;
                if(fibb.compareTo(a)>=0 && fibb.compareTo(b)<=0)ans++;
                if(fiba.compareTo(b)>0 || fibb.compareTo(b)>0)break;
                fiba=fiba.add(fibb);
                fibb=fibb.add(fiba);
            }
            System.out.println(ans);
        }
    }
}