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. C#数据库连接问题

    最近在看C#,今天下午刚开始接触C#的数据库连接,SQL Server2008,问题如图:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名 ...

  2. neutron DVR

    DVR 简介 DVR 提出的背景 在 Neutron 的网络环境中,跨子网的虚机通信是需要通过 Neutron 的路由器.这既包括不同子网的虚拟机之间的通信,又包括虚拟机与外网之间的通信.在 DVR ...

  3. 一个类似植物大战僵尸的python源码

    # 1 - Import library import pygame from pygame.locals import * import math import random # 2 - Initi ...

  4. 图片和byte[]的互相转换

    //图片的"读"操作 //①参数是图片路径:返回Byte[]类型: //参数是图片的路径 public byte[] GetPictureData(string imagePath ...

  5. hdu 2199 Can you solve this equation? (二分法)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  6. HDU 6203 ping ping ping(贪心+LCA+DFS序+BIT)

    ping ping ping Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  7. [bzoj] 2694 Lcm || 莫比乌斯反演

    原题 定义整数a,b,求所有满足条件的lcm(a,b)的和: 1<=a<=A 1<=b<=B ∀n>1,n2†gcd(a,b)(即任意n>1,\(n^2\)不是gc ...

  8. [模拟赛] StopAllSounds

    Description 小松鼠开心地在树之间跳跃着,突然她停了下来.因为眼前出现了一个 拿着专克超萌小松鼠的法宝----超萌游戏机的游客! 超萌游戏机之所以拥有这个名字,是因为它的屏幕是一个n × 2 ...

  9. poj 2378 Tree Cutting 树形dp

    After Farmer John realized that Bessie had installed a "tree-shaped" network among his N ( ...

  10. 简单瞎搞题(bitset的操作)

    链接:https://www.nowcoder.com/acm/contest/132/C来源:牛客网 题目 一共有 n个数,第 i 个数是 xi  xi 可以取 [li , ri] 中任意的一个值. ...