Uva10183-how many Fibs? (Java large number + two points)

Source: Internet
Author: User

Uva10183-how many Fibs? (Java large number + two points)

Topic links

The main topic: To you a, B, to ask for [A, a] how many fibs number.

Problem-solving ideas: Although A.B is very big, but in 10^100 within the fibs but not more than 500. This allows you to save these fibs in the array, and then each time two points to the location of a, B, and then you can get the number of fibs between.

Code:

Importjava.util.*;Importjava.math.*;Importjava.io.*;Importjava.lang.string.*; Public  class Main {StaticBigInteger f[] =Newbiginteger[10005];Static intn =2; Public Static void Init() {f[1] = biginteger.valueof (1); f[2] = biginteger.valueof (2); BigInteger C = biginteger.valueof (Ten). POW ( -); for(inti =3; F[i-1].compareto (c)! =1; i++) {F[i] = f[i-1].add (F[i-2]);        n++; }    } Public Static int Upper_bound(BigInteger a) {intL =1;intR = N;intM, Num; while(L < R) {m = (L + r)/2; num = A.compareto (f[m]);if(Num <=0) r = m;ElseL = m +1; }returnR } Public Static void Main(String args[]) {Scanner cin =NewScanner (system.in);        Init (); BigInteger A, B; while(Cin.hasnext ())            {a = Cin.nextbiginteger (); b = Cin.nextbiginteger ();if(A.equals (Biginteger.zero) && b.equals (Biginteger.zero)) Break;intx = Upper_bound (b);inty = Upper_bound (a)-1;if(F[x].compareto (b)! =0) x--;                        System.out.println (x-y); }    }}

Uva10183-how many Fibs? (Java large number + two points)

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.