How Many Fibs?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3098    Accepted Submission(s): 1232

Problem Description
Recall the definition of the Fibonacci numbers: 

f1 := 1 

f2 := 2 

fn := fn-1 + fn-2 (n >= 3)

Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a, b]. 

 
Input
The input contains several test cases. Each test case consists of two non-negative integer numbers a and b. Input is terminated by a = b = 0. Otherwise, a <= b <= 10^100. The numbers a and b are given with no superfluous leading zeros.

 
Output
For each test case output on a single line the number of Fibonacci numbers fi with a <= fi <= b. 

 
Sample Input
10 100
1234567890 9876543210
0 0
 
Sample Output
5
4
 

import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
BigInteger f[]=new BigInteger[505];
f[0]=BigInteger.valueOf(1);
f[1]=BigInteger.valueOf(2);
for(int i=2;i<502;i++){
f[i]=f[i-1].add(f[i-2]);
}
while(true){
BigInteger a=input.nextBigInteger();
BigInteger b=input.nextBigInteger();
if(a.equals(BigInteger.ZERO)&&b.equals(BigInteger.ZERO))
break;
int sum=0;
for(int i=0;i<502&&b.compareTo(f[i])>=0;i++){
if(f[i].compareTo(a)>=0)
sum++;
}
System.out.println(sum);
}
}
}

How Many Fibs_hdu_1316(大数).java的更多相关文章

  1. HDU 1715 大数java

    大菲波数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. HDU1134/HDU1133 递推 大数 java

    Game of Connections Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  3. HDU1063 大数 java

    Exponentiation Time Limit: 2000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. Integer Inquiry_hdu_1047(大数).java

    Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. 大数java(pow)

    Problems involving the computation of exact values of very large magnitude and precision are common. ...

  6. java求两个数中的大数

    java求两个数中的大数 java中的max函数在Math中 应用如下: int a=34: int b=45: int ans=Math.max(34,45); 那么ans的值就是45.

  7. CF1245 A. Good ol' Numbers Coloring(java与gcd)

    题意:给定数字A和数字B,问是否满足gcd(A,B)==1. 思路:可以直接写函数gcd.也可以用大数自带的gcd功能. 代码1: /* @author nimphy @create 2019-11- ...

  8. HDU 5686:2016"百度之星" - 资格赛 Problem B

    原文链接:https://www.dreamwings.cn/hdu5686/2645.html Problem B Time Limit: 2000/1000 MS (Java/Others)    ...

  9. 2016百度之星资格赛 Round1(2,3,4题)

    Problem B Accepts: 2515 Submissions: 9216 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...

随机推荐

  1. HDU 2369 Broken Keyboard(字符串)

    点我看题目 题意 : 这个人的键盘坏了,最多只能按n个键,给你一串字符串,问你找一个最长的字串,这个字串中包含的不同的字母不能超过n个. 思路 : 比赛的时候脑子没转过来,一直没模拟出来,都不知道怎么 ...

  2. Vmware 8.00 文件共享ubuntu

    http://bolg.sinaapp.com/html/2012/1848.html 这是解决vm不能共享的解决方案. 今天学会的Linux命令: cp -i *** ~/tmp cd VMware ...

  3. NGUI所见即所得之UIAtlasMaker , UIAtlas (2)

    本文的重点就是要将NGUI把多张图片打成一个图集(Atlas)的原理和过程研究下,学习下Unity提供的api和NGUI写的功能以及设计思想. (原文链接) 其它链接:NGUI所见即所得之UIRoot ...

  4. 将手机micro USB口转换为USB type C连接器的低成本方案

    我们知道USB IF提出的type C连接器的终极目标是统一各种USB 接口. 尽管USB 3.0在PC市场上发展的风生水起,但是由于USB 3.0对手机4G LTE的EMI和RFI干扰,导致市场上除 ...

  5. 关于标准库中的ptr_fun/binary_function/bind1st/bind2nd

    http://www.cnblogs.com/shootingstars/archive/2008/11/14/860042.html 以前使用bind1st以及bind2nd很少,后来发现这两个函数 ...

  6. php陷阱:字符串和数字比较

    PHP中的比较运算符有点诡异,很容易出错,现列出比较规则: 1.当两个字符进行大小比较时,是比较着这两个字符的ASCII码大小——这条很容易理解. 2.当两个字符串进行大小比较时,是从第一个字符开始, ...

  7. proc 文件系统调节参数介绍

    /proc/net/* snmp文件 Ip: ip项 Forwarding        : 是否开启ip_forward,1开启,2关闭 DefaultTTL       : IP默认ttl. In ...

  8. BZOJ_1607_ [Usaco2008_Dec]_Patting_Heads_轻拍牛头_(筛数)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1607 给出一组n个数,求每个数能被多少个其他的数整除. 分析 暴力一点的做法就是每个数去筛它的 ...

  9. Mac OS X 10.10(yosemite)更新后,cocoapods出错, 及cocoapods更新至0.34后, 错误情况整理

    1:Mac升级10.10后,执行pod install出错如下 QTX-Will-mini:NewHishop willbin$ pod install [!] Unable to load a sp ...

  10. JS中String,Math常用函数

    String对象: 1.length属性 说明:获取字符串的长度 实例: var str="abc"; var i=str.length;//output:3 2.charAt() ...