首页 技术 正文
技术 2022年11月20日
0 收藏 417 点赞 4,917 浏览 1224 个字

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 DescriptionRecall 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].  InputThe 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. OutputFor each test case output on a single line the number of Fibonacci numbers fi with a <= fi <= b.  Sample Input10 1001234567890 98765432100 0 Sample Output54 

 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);         }     } }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,581
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918