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. 周末“干活”之 Mesos Meetup

    周末两天都是大雾霾天,作为运营也不能在家宅,告别了技术就得腿儿勤点儿. 非常感谢 Linker 的 Sam Chen 和 数人科技 的 CTO 共同组织的Mesos Meetup,OneAPM 最帅的 ...

  2. HDOJ多校联合第六场

    先一道一道题慢慢补上, 1009.题意,一棵N(N<=50000)个节点的树,每个节点上有一个字母值,给定一个串S0(|S0| <=30),q个询问,(q<=50000),每次询问经 ...

  3. plsql exist和in 的区别

    <![endif]--> <![endif]--> 发现公司同事很喜欢用exists 和in 做子查询关联,我觉得很有必要研究下 两者的区别,供参考和备忘 /* (这段信息来自 ...

  4. Java之关键字static和final的使用

    static 在Java中声明属性.方法时,可使用关键字static来修饰. 1.static变量       按照是否静态的对类成员变量进行分类可分两种:一种是被static修饰的变量,叫静态变量或 ...

  5. C++ CGI Helloword

    一 什么是CGI CGI(The Common Gateway Interface):通用网关接口,定义web服务器和客户脚本进行信息交互的一系列标准.  二 web浏览器 为了了解CGI的概念,让我 ...

  6. windows播放声音

    一般播放MP3常见的有两种方法,一种是自己解码,另外一种用系统的库,比如MCI,当然如果可以用控件直接用个控件会更方便. 1.      使用mci #include <windows.h> ...

  7. [解决] [centOS] g++ 带 -static 参数编译时,报错 /usr/bin/ld: cannot find -lm

    静态编译时缺少某个库 yum install glibc-static 从这里找到的 http://www.linuxquestions.org/questions/linux-software-2/ ...

  8. Android 实用代码七段(一)

    前言 这里积累了一些不常见确又很实用的代码,每收集7条更新一次,希望能对大家有用. 声明 欢迎转载,但请保留文章原始出处:)  博客园:http://www.cnblogs.com 农民伯伯: htt ...

  9. nginx优化之请求直接返回json数据

    对于有些服务端接口返回是固定值的json,可通过配置nginx直接返回json,减少程序的加载对资源的占用,减少接口响应时间 location ~* (request/update)$ {     d ...

  10. FZU2224 An exciting GCD problem 区间gcd预处理+树状数组

    分析:(别人写的) 对于所有(l, r)区间,固定右区间,所有(li, r)一共最多只会有log个不同的gcd值, 可以nlogn预处理出所有不同的gcd区间,这样区间是nlogn个,然后对于询问离线 ...