import java.util.*;
import java.util.regex.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.*;
import java.math.*;
import java.text.*;
class Main
{
public static void main (String args[]) // entry point from OS
{
Main myWork = new Main(); // create a dynamic instance
myWork.Begin(); // the true entry point
}
void Begin()
{
Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter pr=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
/*
try
{
sc=new Scanner(new File("INPUT.TXT"));
pr=new PrintWriter(new File("OUTPUT.TXT"));
}
catch(Exception e)
{
System.exit(0);
}*/
ArrayList abc=new ArrayList(500);
abc.add(new BigInteger("1"));
abc.add(new BigInteger("2"));
BigInteger b1=new BigInteger("1");
BigInteger b2=new BigInteger("2");
BigInteger tmp=new BigInteger("0");
BigInteger tmp2=new BigInteger("0");
BigInteger a=new BigInteger("0");
BigInteger b=new BigInteger("0");
BigInteger lpcntr=new BigInteger("0");
BigInteger cntr=new BigInteger("0");
int x=0,y=0,t=0;
for(int i=2;i<501;i++)
{
tmp=b2;
b2=b1.add(b2);
b1=tmp;
abc.add(i,b2);
}
Collections.sort(abc);
for(;;)
{
t=0;
a=sc.nextBigInteger();
b=sc.nextBigInteger();
if(a.compareTo(BigInteger.ZERO)==0 && b.compareTo(BigInteger.ZERO)==0) break;
if(a.compareTo(b)>0)
{
tmp2=a;a=b;b=tmp2;
}
x=Collections.binarySearch(abc,a);
if(x<0){x=x+1;x = -1*x;t=t+1;}
y=Collections.binarySearch(abc,b);
if(y<0){y=y+1;y = -1*y; y=y-1;t=t+1;}
if(a.compareTo(b)==0 && t==0)
pr.printf("1%n");
else
pr.printf("%d%n",(y-x)+1);
}
pr.close();
sc.close();
}
}
No comments:
Post a Comment