HDU 1316 how many fibs? [Java large number]

Source: Internet
Author: User

How many fibs?

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 2814 accepted submission (s): 1112


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 Input

10 1001234567890 98765432100 0
 


Sample output

54
 


Sourceuniversity of Ulm Local contest 2000


Recommendeddy

I drilled the Java hole again, and then I got the AC,

But the strange thing is, why do I reduce the memory by half and the space is not saved much? Instead, the time is longer.

8276754 16:30:33 Accepted 1316 171 Ms 3704 K 955 B Java Freeze
8276732 16:28:32 Accepted 1316 140 ms 3752 K 958 B Java Freeze
Import Java. util. *; import Java. math. *; import Java. io. *; public class main {public static void main (string ARGs []) {biginteger [] f = new biginteger [500]; f [1] = new biginteger ("1"); F [2] = new biginteger ("2"); For (INT I = 3; I <500; I ++) {f [I] = f [I-1]. add (F [I-2]);}/* string S = f [499]. tostring (); // calculates that there are 105 int Len = S. length (); system. out. println (LEN); */partition CIN = new partition (New bufferedinputstream (system. in); biginteger a, B; biginteger c = biginteger. valueof (0); While (CIN. hasnextbiginteger () {A = cin. nextbiginteger (); B = cin. nextbiginteger (); if (. compareto (biginteger. valueof (0) = 0 & B. compareto (c) = 0) {break;} int ans = 0; For (INT I = 1; I <500; I ++) {If (F [I]. compareto (B) = 1) {break;} If (F [I]. compareto (a)> = 0 & F [I]. compareto (B) <= 0) {ans ++ ;}} system. out. println (ANS );}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.