杭电1316(How Many Fibs?)
来源:互联网 发布:55开和笑笑 知乎 编辑:程序博客网 时间:2024/06/06 12:46
点击打开杭电1316
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].
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 1001234567890 98765432100 0
Sample Output
54
代码实现
import java.math.BigInteger;import java.util.Scanner;class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); BigInteger[] fib=new BigInteger[1005]; fib[1]=BigInteger.valueOf(1); fib[2]=BigInteger.valueOf(2); for(int i=3;i<1005;i++){ fib[i]=fib[i-1].add(fib[i-2]); } int numb; while(sc.hasNextBigInteger()){ BigInteger a=sc.nextBigInteger(); BigInteger b=sc.nextBigInteger(); if(a.equals(BigInteger.valueOf(0))&&b.equals(BigInteger.valueOf(0))){ break; } numb=0; for(int i=1;i<1005;i++){ if(fib[i].compareTo(a)>=0&&fib[i].compareTo(b)<=0){ numb++; } if(fib[i].compareTo(b)>0){ break; } } System.out.println(numb); } }}
0 0
- 杭电1316(How Many Fibs?)
- 杭电oj-1316-How Many Fibs?
- 杭电OJ(HDOJ)1316题:How many Fibs?(大数操作——比较)
- HDU 1316 -- How Many Fibs?(Java)
- 第四届图灵杯->How Many Fibs?(1316)
- POJ 2413 How many Fibs? /HDOJ 1316 How Many Fibs?
- HDU 1316 How Many Fibs?
- HDU 1316 How Many Fibs?
- HDOJ 1316 How Many Fibs?
- HDU 1316 How Many Fibs?
- hdu 1316 How Many Fibs?
- HDOJ 1316 How Many Fibs?
- hdu 1316 How Many Fibs?
- HDUJ 1316 How Many Fibs?
- HDU 1316 How Many Fibs?
- HDUOJ - 1316 How Many Fibs?
- hdu 1316 How Many Fibs?
- hdu 1316 How Many Fibs?
- C语言实现直接插入排序
- android入门:单击按钮显示当前时间
- Ubuntu linux GRUB2 安装和修复
- web.xml文件中配置<mime-mapping>下载文件类型
- BZOJ1009 [HNOI2008]GT考试【kmp+矩阵加速DP】
- 杭电1316(How Many Fibs?)
- ubuntu 下 jenkins 的安装与配置
- 第四部分 jQuery中的事件和动画
- 你必须懂的 T4 模板:体系架构
- Java性能调优-简单总结
- Bellman-Ford算法
- nodejs 生成和导出 word
- openCV 图像滤波
- leetcode || 116、Populating Next Right Pointers in Each Node