问题描述:

HD-ACM算法专攻系列(13)——How Many Fibs?

 

源码:

 

import java.math.BigInteger;
import java.util.*;

public class Main
{
		//主函数
        public static void main(String[] args)
        {
            BigInteger a, b, zero = BigInteger.valueOf(0), f1, f2, fn;
			int count;
			Scanner cin = new Scanner(System.in);
			while(true)
			{
				a = cin.nextBigInteger();
				b = cin.nextBigInteger();
				if(a.equals(zero) && b.equals(zero))break;
				count = 0;
				f1 = BigInteger.valueOf(1);
				if(a.compareTo(f1) <= 0 && b.compareTo(f1) >= 0)count++;
				f2 = BigInteger.valueOf(2);
				if(a.compareTo(f2) <= 0 && b.compareTo(f2) >= 0)count++;
				while(true)
				{
					fn = f2.add(f1);
					if(a.compareTo(fn) <= 0 && b.compareTo(fn) >= 0)count++;
					else if(b.compareTo(fn) < 0)break;
					f1 = f2;
					f2 = fn;
				}
				System.out.println(count);
			}
		}
}
 

  

相关文章:

  • 2021-07-01
  • 2021-12-25
  • 2021-06-12
  • 2021-09-10
  • 2021-10-25
  • 2021-06-17
  • 2021-12-28
  • 2021-12-28
猜你喜欢
  • 2021-11-14
  • 2021-11-15
  • 2021-12-30
  • 2022-01-17
  • 2021-06-20
  • 2022-01-27
  • 2021-10-29
相关资源
相似解决方案