How Many Fibs?

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

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.util.Scanner;
 import java.math.*;

 /**
  * @author 日天大帝
  * 第480个斐波数是101位,打个表开480够用
  */
 public class Main {
     public static void main(String[] args) {
         Scanner cin = new Scanner(System.in);
         final int MAX = 480;
         BigInteger arr[] = new BigInteger[MAX];
         arr[0] = BigInteger.ONE;
         arr[1] = BigInteger.valueOf(2);
         for(int i=2; i<MAX ; ++i){
             arr[i] = arr[i-1].add(arr[i-2]);
         }
         while(cin.hasNext()){
             BigInteger a = cin.nextBigInteger();
             BigInteger b = cin.nextBigInteger();
             if(a.compareTo(b) == 0 && a.compareTo(BigInteger.ZERO) == 0)break;
             int ct = 0;
             for(int i=0;; ++i){
                 if(arr[i].compareTo(b) > 0)break;
                 if(arr[i].compareTo(a) >= 0)ct++;
             }
             System.out.println(ct);
         }
     }
 }

hdu--1316--How Many Fibs?(java大数)的更多相关文章

  1. hdu 1316 How Many Fibs?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1316 How Many Fibs? Description Recall the definition ...

  2. hdu 4043 FXTZ II [ 概率 + Java大数]

    传送门 FXTZ II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. HDU 1316 How Many Fibs?(java,简单题,大数)

    题目 /** * compareTo:根据该数值是小于.等于.或大于 val 返回 -1.0 或 1: public int compareTo(BigInteger val) 将此 BigInteg ...

  4. hdu 1316 How many Fibs?(高精度斐波那契数)

    //  大数继续 Problem Description Recall the definition of the Fibonacci numbers:  f1 := 1  f2 := 2  fn : ...

  5. Buy the Ticket HDU 1133 卡特兰数应用+Java大数

    Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...

  6. hdu 1316 How Many Fibs? (模拟高精度)

    题目大意: 问[s,e]之间有多少个 斐波那契数. 思路分析: 直接模拟高精度字符串的加法和大小的比較. 注意wa点再 s 能够从 0 開始 那么要在推断输入结束的时候注意一下. #include & ...

  7. HDU高精度总结(java大数类)

      HDU1002   A + B Problem II [题意]大数相加 [链接]http://acm.hdu.edu.cn/showproblem.php?pid=1002 Sample Inpu ...

  8. hdu 1042 N! java大数及判断文件末尾

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submi ...

  9. 【百度之星】【java大数+C++做法】hdu 6719 Strassen

    代码:递归搜索一下.java大数做法 import java.util.*; import java.math.*; import java.security.MessageDigest; publi ...

随机推荐

  1. java 得到uuid并处理

    java 得到uuid String s = UUID.randomUUID().toString(); //去掉“-”符号 return s.substring(0,8)+s.substring(9 ...

  2. textarea禁止拖拽

    <textarea style="resize:none;" ></textarea>'

  3. jquery(select)下拉框 选取选中的值

    var get_date_type=$("#date_type").find("option:selected").val(); var get_date_ty ...

  4. php获取当天的开始时间和结束时间戳

    $begin_time=date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d'),date('Y')));$over_time=dat ...

  5. MySQL的四种事务隔离级别

    本文实验的测试环境:Windows 10+cmd+MySQL5.6.36+InnoDB 一.事务的基本要素(ACID) 1.原子性(Atomicity):事务开始后所有操作,要么全部做完,要么全部不做 ...

  6. XML读取两种方法

    //第一种SAX方法解析 package a20170722.xmlex; import java.io.File; import java.util.ArrayList; import java.u ...

  7. JavaScript 原型与继承机制详解

    引言 初识 JavaScript 对象的时候,我以为 JS 是没有继承这种说法的,虽说 JS 是一门面向对象语言,可是面向对象的一些特性在 JS 中并不存在(比如多态,不过严格来说也没有继承).这就困 ...

  8. 基于vue2.0的一个豆瓣电影App

    1.搭建项目框架 使用vue-cli 没安装的需要先安装 npm intall -g vue-cli 使用vue-cli生成项目框架 vue init webpack-simple vue-movie ...

  9. 【Mysql基本知识整理】

    一.简介 1.什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,每个数据库都有一个或多个不同的API用于创建,访问,管理,搜索和复制所保存的数据. 2.关系型数据库 ...

  10. Oracle两张表关联批量更新其中一张表的数据

    Oracle两张表关联批量更新其中一张表的数据 方法一(推荐): UPDATE 表2 SET 表2.C = (SELECT B FROM 表1 WHERE 表1.A = 表2.A) WHERE EXI ...