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. RecyclerView一个奇怪的npe异常

    java.lang.NullPointerException at android.support.v7.widget.RecyclerView.computeVerticalScrollOffset ...

  2. tlplayer,wzplayer支持wince,winphone,windows8 for arm

    tlplayer,wzplayer宣布支持wince,winphone,windows8 for arm,支持http,hls,rtmp,rtsp,mms等媒体流协议. 支持加密视频播放. 目前tlp ...

  3. vim多标签,多窗口

    多标签 进入vim前 vim -p <文件名> 以多标签形式打开文件.如vim -p * 就是编辑当前目录的所有文件, vim编辑中 :tabnew 增加一个标签 :tabc 关闭当前的t ...

  4. hdu4681String

    http://acm.hdu.edu.cn/showproblem.php?pid=4681 枚举A串和B串包含C串的区间  枚举区间端点算左右两端最长公共子序 #include <iostre ...

  5. Hadoop中的各种排序

    本篇博客是金子在学习hadoop过程中的笔记的整理,不论看别人写的怎么好,还是自己边学边做笔记最好了. 1:shuffle阶段的排序(部分排序) shuffle阶段的排序可以理解成两部分,一个是对sp ...

  6. BZOJ_1270_雷涛的小猫_(动态规划)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1270 有n棵树,高度为h.一只猫从任意一棵树的树顶开始,每次在同一棵树上下降1,或者跳到其他树 ...

  7. ☀【JS】检测属性

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

  8. 【转】VIRTUALBOX导入已有.VDI文件步骤

    原文网址:http://blog.csdn.net/wanghai__/article/details/6703923 1.安装SUN VIRTUALBOX 2.新建,进入到“新建虚拟电话”对话框,下 ...

  9. C# String.Format大全

    C# String.Format大全 ? ? ? 十进制的数字 ? ? string.Format("{0:D3}",23) 023 格式化十进制的数字 string.Format ...

  10. Node.js 创建第一个应用

    如果我们使用PHP来编写后端的代码时,需要Apache 或者 Nginx 的HTTP 服务器,并配上 mod_php5 模块和php-cgi. 从这个角度看,整个"接收 HTTP 请求并提供 ...