杭电 1316 How Many Fibs?

import java.io.*;

import java.util.*;

import java.math.*;

public class Main {

       public static void main(String args[])

       {

    	   Scanner cin=new Scanner(System.in);

    	   BigInteger f[]=new BigInteger[505];

    	   f[1]=BigInteger.valueOf(1);

    	   f[2]=BigInteger.valueOf(2);

    	   for(int i=3;i<505;i++)

    	   {

    		   f[i]=f[i-1].add(f[i-2]);

    	   }

    	   BigInteger a,b;

    	   while(cin.hasNextBigInteger())

    	   {

    		   a=cin.nextBigInteger();

    		   b=cin.nextBigInteger();

    		   if(a.compareTo(BigInteger.ZERO)==0&&b.compareTo(BigInteger.ZERO)==0)

    		   {

    			   break;

    		   }

    		   int count=0;

    		   for(int i=1;i<505;i++)

    		   {

    			   if(f[i].compareTo(b)>0)

    				   break;

    			   if(f[i].compareTo(a)>=0&&f[i].compareTo(b)<=0)

    			   {

    				   count++;

    			   }

    		   }

    		   System.out.println(count);

    	   }

       }

}

  

你可能感兴趣的:(man)