How Many Fibs?

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

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
 
 
Java大整数
import java.math.BigInteger;
import java.util.Scanner; public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger[] fib = new BigInteger[];
BigInteger MAX = BigInteger.valueOf().pow();
fib[] = BigInteger.valueOf();
fib[] = BigInteger.valueOf();
for(int i=;i<=;i++){
fib[i] = fib[i-].add(fib[i-]);
// System.out.println(fib[i]);
}
while(sc.hasNext()){
String str1 = sc.next();
String str2 = sc.next();
if(str1.equals("")&&str2.equals("")) break;
BigInteger a = new BigInteger(str1);
BigInteger b = new BigInteger(str2);
int start=,end = ;
for(int i=;i<=;i++){
if(fib[i].compareTo(a)>=) {
start = i;
break;
}
}
for(int i=;i<=;i++){
if(fib[i].compareTo(b)==) {
end = i;
break;
}
if(fib[i].compareTo(b)>){
end = i-;
break;
}
}
//System.out.println(start+" "+end);
System.out.println(end-start+);
}
}
}

hdu 1316(大整数)的更多相关文章

  1. hdu 4474 大整数取模+bfs

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4474 (a*10+b)%c = ((a%c)*10+b%c)%c; 然后从高位开始枚举能填的数字填充, ...

  2. hdu 4523(大整数)

    威威猫系列故事——过生日 Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total ...

  3. hdu 1250(大整数)

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. HDU 1212 大整数的取模运算

    因为这里是MOD最大为100000 所以我将字符串看作5个一组,并记录后面跟了多少个100000 每次取5个数根据其数据进行取模更新 注意过程中 100000*100000会超int #include ...

  5. HDU 1002 A + B Problem II(大整数相加)

    A + B Problem II Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u De ...

  6. HDOJ-1002 A + B Problem II (非负大整数相加)

    http://acm.hdu.edu.cn/showproblem.php?pid=1002 输入的数都是正整数,比较好处理,注意进位. //非负大整数加法 # include <stdio.h ...

  7. ocrosoft Contest1316 - 信奥编程之路~~~~~第三关 问题 L: 大整数减法

    http://acm.ocrosoft.com/problem.php?cid=1316&pid=11 题目描述 求两个大的正整数相减的差.   输入 共2行,第1行是被减数a,第2行是减数b ...

  8. poj2389-Bull Math(大整数乘法)

    一,题意: 大整数乘法模板题二,思路: 1,模拟乘法(注意"逢十进一") 2,倒序输出(注意首位0不输出) 三,步骤: 如:555 x 35 = 19425  5 5 5  5 5 ...

  9. AC日记——大整数的因子 openjudge 1.6 13

    13:大整数的因子 总时间限制:  1000ms 内存限制:  65536kB 描述 已知正整数k满足2<=k<=9,现给出长度最大为30位的十进制非负整数c,求所有能整除c的k. 输入 ...

随机推荐

  1. lincode-58-四数之和

    58-四数之和 给一个包含n个数的整数数组S,在S中找到所有使得和为给定整数target的四元组(a, b, c, d). 注意事项 四元组(a, b, c, d)中,需要满足a <= b &l ...

  2. 转:C++中临时对象及返回值优化

    http://www.cnblogs.com/xkfz007/articles/2506022.html 什么是临时对象? C++真正的临时对象是不可见的匿名对象,不会出现在你的源码中,但是程序在运行 ...

  3. SQL Server 监测语句

    qs.creation_time, last_execution_time, total_physical_reads, total_logical_reads, total_logical_writ ...

  4. php开发中处理emoji表情和颜文字的兼容问题

    背景:随着手机的普及,现在移动开发很火爆,已经远远超过了pc端.在移动设备经常会发生用户发送的内容中包含emoji表情,在显示时就是乱码.一般是因为Mysql表设计时,都是用UTF8字符集的.把带有e ...

  5. Zebra - zebra command to get printer status

    /// <summary> /// determine whether the network printer is in pause. /// </summary> /// ...

  6. pptp协议的工作原理

    我的工作机是A,通信网卡是Aeth0, Appp0: 然后我的云主机是B, 通信的网卡是Beth0, Bppp0: 在网卡Bppp0上会不断地很清晰的数据包: 16:40:39.522917 IP 6 ...

  7. 免费的dns服务器(更换dns服务器有时可以解决某些网站(如爱奇艺访问不了的问题))

    首先百度提供的dns就是非常好用的dns,小编就把百度的dns作为首选180.76.76.76.   其次是阿里提供的dns223.5.5.5,响应速度非常的快,而且没有广告劫持.   再就是最通用的 ...

  8. 通过7zip压缩备份文件bat

    for %%X in (*log20*) do "c:\Program Files\7-Zip\7z.exe" a "backups\%%X.zip" &quo ...

  9. Linux 下打包报错:enospc (no space left on device)

    昨天打了个包,早上发现很多页面js加载404,一查原来打包的min文件夹下是空的,打包出错了 Error code: enospc du -sh * rm -f 文件名称 rm -rf 目录名称 前端 ...

  10. 关于applePay详细讲解

    https://www.cnblogs.com/diweinan/p/6225501.html