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大整数
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. BigInteger[] fib = new BigInteger[];
  8. BigInteger MAX = BigInteger.valueOf().pow();
  9. fib[] = BigInteger.valueOf();
  10. fib[] = BigInteger.valueOf();
  11. for(int i=;i<=;i++){
  12. fib[i] = fib[i-].add(fib[i-]);
  13. // System.out.println(fib[i]);
  14. }
  15. while(sc.hasNext()){
  16. String str1 = sc.next();
  17. String str2 = sc.next();
  18. if(str1.equals("")&&str2.equals("")) break;
  19. BigInteger a = new BigInteger(str1);
  20. BigInteger b = new BigInteger(str2);
  21. int start=,end = ;
  22. for(int i=;i<=;i++){
  23. if(fib[i].compareTo(a)>=) {
  24. start = i;
  25. break;
  26. }
  27. }
  28. for(int i=;i<=;i++){
  29. if(fib[i].compareTo(b)==) {
  30. end = i;
  31. break;
  32. }
  33. if(fib[i].compareTo(b)>){
  34. end = i-;
  35. break;
  36. }
  37. }
  38. //System.out.println(start+" "+end);
  39. System.out.println(end-start+);
  40. }
  41. }
  42. }

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. css如何选择相同class下的第一个class元素和最后一个元素?

    如图,如果像选择类名为  class="exerciseInfo"  中的第一个和最后一个div,做法如下: 选择第一个类名: .exerciseInfo: nth-of-type ...

  2. [剑指Offer] 7.斐波那契数列

    class Solution { public: int Fibonacci(int n) { ] = {}; res[] = ; res[] = ; ;i < n;i ++){ res[i] ...

  3. mac tomcat: error 1 operation not permitted

    在用微信传一个tomcat压缩包到别人后,解压后无法用idea启动,提示 error 1 operation not permitted,但是直接用命令可以执行. 仔细查看,原来是因为mac出于安全考 ...

  4. 条件查询Criteria

    public User getUserByNameCri(String name){ Session session = null; User user = null; try { session = ...

  5. BZOJ4487 JSOI2015染色问题(组合数学+容斥原理)

    逐个去除限制.第四个限制显然可以容斥,即染恰好c种颜色的方案数=染至多c种颜色的方案数-染至多c-1种颜色的方案数+染至多c-2种颜色的方案数…… 然后是限制二.同样可以容斥,即恰好选n行的方案数=至 ...

  6. NAS星云链 入门之从零开发第一个DAPP

    应该有很多小伙伴和我一样,一直想去入手学习区块链,但是总无从下手,有些概念感觉理解了,有感觉没理解.其实这都是“没实践”的锅. 所谓看十遍不如想一遍,想一遍不如做一遍.这不最近星云链nebulas正有 ...

  7. Spring学习--使用 utility scheme 定义集合及 p命名空间

    util schema 定义集合: 使用基本的集合标签定义集合时 , 不能将集合作为独立的 Bean 定义 , 导致其他 Bean 无法引用该集合 , 所以无法在不同 Bean 之间共享集合. 可以用 ...

  8. JavaScript 知识点之escape()与decodeURI()

    解释:escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法:escape(string)参数描述string必需.要被转义或编码的字符串. 返回值:已编码的 str ...

  9. 转:RBAC权限控制

    名词解释: RBAC:Role-Based Access Control,基于角色的访问控制   关键词: RBAC,Java Shiro,Spring Security,   一. RBAC 要解决 ...

  10. Mybatis如何查询部分字段

    解决问题:数据库表里面很多字段不太需要,有时只想取到里面的部分字段的值,如果重新定义 DTO 会比较麻烦. BookMapper.xml 文件中定义如下: ` <!-- Book全部字段 --& ...