HDUJ 1316 How Many Fibs?
来源:互联网 发布:php视频网站源码下载 编辑:程序博客网 时间:2024/05/21 11:24
How Many Fibs?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4106 Accepted Submission(s): 1623
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.util.Scanner;import java.math.BigInteger;public class yhrtr {public static void main(String[] args) {Scanner cin = new Scanner (System.in);BigInteger s[] = new BigInteger[1010];s[1] = new BigInteger("1");s[2] = new BigInteger("2");for(int i=3;i<=1005;i++)s[i] = s[i-1].add(s[i-2]);BigInteger a,b,c;while(cin.hasNext()){a = cin.nextBigInteger();b = cin.nextBigInteger();if(a.compareTo(BigInteger.ZERO)==0 && b.compareTo(BigInteger.ZERO)==0)return ;if(a.compareTo(b)>0){c = a;a = b;b = c;}int sum = 0;for(int i=1;i<=1005;i++){if(s[i].compareTo(a)>=0 && s[i].compareTo(b)<=0)sum++;}System.out.println(sum);}}}
0 0
- HDUJ 1316 How Many Fibs?
- 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?
- HDU 1316 How Many Fibs?
- HDUOJ - 1316 How Many Fibs?
- hdu 1316 How Many Fibs?
- hdu 1316 How Many Fibs?
- hdu 1316 How Many Fibs?
- hdu 1316 How Many Fibs?
- hdu 1316 How Many Fibs?
- HDU 1316 How Many Fibs?
- hdu 1316 How Many Fibs?
- 字符串基础及常用算法
- 1407280912-hd-第几天?.cpp
- 【Java】变量初始化顺序
- 安装LUA报错
- 【codeforce^5COMBO】#79-84 2014_Summer_Crazy @20140727
- HDUJ 1316 How Many Fibs?
- V4L2 Video Capture - 01
- js中常用的一些方法
- cocos2d-x游戏从win32平台移植Android平台
- Unsupported major.minor version 51.0
- 如何快速将pdf转换成excel转换器
- Qt中 QString 和int, char等的“相互”转换
- Spring验证详解
- Notification(四)——Notification完整使用实例详解