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. 标准C++中的string类的用法总结(转)

    http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.html 相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的 ...

  2. Asp.net MVC 视图之公用代码

    一.公共模板 转自:http://www.cnblogs.com/kissdodog/archive/2013/01/07/2848881.html 1.@RenderBody() 在网站公用部分通过 ...

  3. OpenSSL 与 SSL 数字证书概念贴

    SSL/TLS 介绍见文章 SSL/TLS原理详解(http://seanlook.com/2015/01/07/tls-ssl). 如果你想快速自建CA然后签发数字证书,请移步 基于OpenSSL自 ...

  4. Eclipse使用技巧及个性化设计

    以下除特殊说明均在 Windows->Preferences里面操作 如何把Eclipse关闭提示调出来? General->Startup and Shutdown,在 Confirm ...

  5. mapreduce: 揭秘InputFormat--掌控Map Reduce任务执行的利器

    随着越来越多的公司采用Hadoop,它所处理的问题类型也变得愈发多元化.随着Hadoop适用场景数量的不断膨胀,控制好怎样执行以及何处执行map任务显得至关重要.实现这种控制的方法之一就是自定义Inp ...

  6. mapreduce实现"浏览该商品的人大多数还浏览了"经典应用

    输入: 日期    ...cookie id.        ...商品id.. xx            xx                        xx 输出: 商品id        ...

  7. ASP.NET MVC Overview

    ASP.NET MVC Overview The Model-View-Controller (MVC) architectural pattern separates an application  ...

  8. JS中的substring和substr函数的区别

    1. 在JS中, 函数声明: stringObject.substring(start,stop) start是在原字符串检索的开始位置,stop是检索的终止位置,返回结果中不包括stop所指字符. ...

  9. 【转】CUDA5/CentOS6.4

    转载自http://wenzhang.baidu.com/article/view?key=076f36658dd0828c-1393896446 This article explains how ...

  10. [未解出,hzwer]挖掘机

    挖掘机(dig.*) 背景 附中机房谁最虚?高二一班***!感觉很顺,是吧? 题目描述 今天,丧尸czy开着挖掘机去上学(……).但是他发现他的mz满天下,所以一路上他碰到了好多他的mz.一开始他以1 ...