Fibonacci Sequence Large number addition hdu1316

Source: Internet
Author: User
A-how Many fibs? crawling in process ... crawling failed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64D &%i64u

Description We define the Fibonacci sequence as follows: F1=1 f2=2 f (n) =f (n-1) +f (n-2) (n>=3) Now, given two numbers a and B, calculate how many Fibonacci numbers are between A and B (including boundaries).

Input input contains multiple sets of test data, each set of test data is two nonnegative integers a and B, and when a and B are equal to 0 o'clock, the program ends. 0<=A<=B<=10^100, note that both A and b do not show a leading 0 (that is, the first 0).

Output

The number of outputs between A and B (satisfying the number of a<=f (i) <=b).

Sample Input 10 100 1234567890 9876543210 0 0

Sample Output 5 4

This kind of problem uses the traditional high precision too time-consuming, direct Java

Import

java.io.*;   
Import java.math.biginteger;   
Import java.util.*; 

Public Classmain {

public static void Main (string[] args) {
Scanner cin=newscanner (system.in);
BigInteger A[]=new biginteger[10500];
A[1]=biginteger.one;
A[2]=biginteger.valueof (2);
for (int i=3; i<10500; i++)
A[i]=a[i-1].add (a[i-2);
int sum;
while (Cin.hasnextbiginteger ()) {
Sum=0
BigInteger X=cin.nextbiginteger ();
BigInteger Y=cin.nextbiginteger ();
if (x.equals (Biginteger.zero) &&y.equals (Biginteger.zero))
break;
for (int i=1;i<10500; i++) {
if (A[i].compareto (x) >=0&&a[i].compareto (y) <=0)
sum++;
}
System.out.println (sum);
}
}

}

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.