How Many Fibs? 字符串转换处理
1 import java.util.*; 2 import java.io.*; 3 import java.lang.*; 4 import java.math.*; 5 import java.text.*; 6 class Main 7 { 8 public static void main(String args[]) 9 { 10 Scanner cin=new Scanner(System.in); 11 int i,j=0,k=0,flags; 12 BigInteger a,b,c[]=new BigInteger[501]; 13 c[0]=BigInteger.valueOf(1); 14 c[1]=BigInteger.valueOf(2); 15 String s1,s2; 16 for(i=2;i<500;i++) 17 { 18 c[i]=c[i-1].add(c[i-2]); 19 } 20 while(cin.hasNext()) 21 { 22 flags=0; 23 s1=cin.next(); 24 s2=cin.next(); 25 a=new BigInteger(s1); 26 b=new BigInteger(s2); 27 if(b.compareTo(BigInteger.valueOf(0))==0)break; 28 for(i=0;i<500;i++) 29 { 30 if(flags==0) 31 { 32 if(c[i].compareTo(a)>=0) 33 { 34 j=i; 35 flags=1; 36 } 37 } 38 if(c[i].compareTo(b)==1) 39 { 40 k=i; 41 break; 42 } 43 } 44 System.out.println(k-j); 45 } 46 } 47 }