How many Fibs?Time
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 5822 Accepted Submission (s): 2267
Problem Descriptionrecall the definition of the Fibonacci numbers:
F1: = 1
F2: = 2
fn: = fn-1 + fn-2 (n >= 3)
Given numbers A and B, calculate how many Fibonacci numbers is in the range [A, b].
Inputthe input contains several test cases. Each test case consists of the non-negative integer numbers a and B. Input is terminated by a = b = 0. Otherwise, a <= b <= 10^100. The numbers A and B is given with no superfluous leading zeros.
Outputfor Each test case is output on a, the number of Fibonacci numbers fi with a <= fi <= B.
Sample Input
10 1001234567890 98765432100 0
Sample Output
54
Sourceuniversity of ULM Local Contest 2000
original title link: http://acm.hdu.edu.cn/showproblem.php?pid=1316
Test Instructions: asks how many fib numbers are in the specified interval.hit the table decisively, and all the fib numbers are sorted in the array, but what is the length of the array? The limit of the number of FIB numbers in the topic is 10^100, and the number of FIB numbers is unknown, so the array size must be determined first!
AC Code:
Import Java.math.bigdecimal;import Java.util.scanner;public class Main {public static void main (string[] args) {Scanner s c = new Scanner (system.in); final int maxn = 1000+5; BigDecimal [] A = new bigdecimal[maxn];a[1]=new BigDecimal (1); A[2]=new BigDecimal (2); for (int i = 3; I <MAXN; i++) {a[i ] = A[i-1].add (A[i-2]);} System.out.println (a[maxn-1]);//system.out.println (a[maxn-1].tostring (). Length ()); while (Sc.hasnext ()) { BigDecimal start = Sc.nextbigdecimal (); BigDecimal end = Sc.nextbigdecimal (); BigDecimal zero = bigdecimal.zero;if (Start.compareto (zero) ==0&&end.compareto (zero) ==0) {break;} int sum = 0;for (int i = 1; i < MAXN; i++) {if (A[i].compareto (start) <0) {continue;} else if (A[i].compareto (end) >0) {break;} else{sum++;}} SYSTEM.OUT.PRINTLN (sum);}}}
HDU 1316 how many Fibs? (Big fib number, or Java Dafa good)