Number Theory: High Precision --- ultraviolet A 10183: How many fibs?

Source: Internet
Author: User
How many fibs?

Description

Recall the definition of the Fibonacci numbers:
f1 := 1 
f2 := 2
fn := f
N-1
 + f
N-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 <= 10100. 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

 

Mean: 

Given two integers A and B, the number of Fibonacci numbers in the statistical interval [a, B.

Analyze:

T because the input range of this question has reached 10 ^ 100, it must be accurate.

We first obtain all the Fibonacci numbers less than 10 ^ 100, then input the STA, en, and then perform the location search. Finally, we can see the answer when we see the positions of STA and en.

Time Complexity:O (N)

 

Source code:

 

/* _ Ooooo _ o8888888o 88 ". "88 (|-_-|) O \=/o ____/'---'\____. '\\| | //'. /\| |: | // _ | -: -| \-// | \ _ | ''\ ---/'' | \. -\__'-'___/-. /___'.. '/--. --\'.. __. "" '<'. ___ \_< |> _/___. '> '"". | :'-\'.; '\_/';. '/-': | \\'-. \___\/___/. -'// ====== '-. ____'-. ___\_____/___. -'____. -'= --- =' ^ ^ ......... .................................... The bug in the bucket of the bucket. When you wake up, you can only sit on the Internet, and get drunk and sleep. When you wake up, you can get online for the next year. I hope that the old computer room will not bow to the boss; Mercedes Benz and BMW are interesting, and the bus programmers are themselves. When others laugh at me, I laugh at myself, and my life is so cheap. If I don't see the beautiful girl on the street, which is my programmer? * // Memory time // 1347 K 0 Ms //: snarl_jsb # include <algorithm> # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # include <Stack> # include <map> # include <string> # include <climits> # include <cmath> # define Max 1100 # define ll long longusing namespace STD; vector <string> maid; string maid (string F1, string F2) {string Buff; int carry = 0, len1 = f1.length (), len2 = f2.length (); for (INT I = 0; I <len1; I ++) {carry = (F1 [I]-'0') + (F2 [I]-'0 ') + carry; char c = carry % 10 + '0'; carry/= 10; buff. push_back (c) ;}for (INT I = len1; I <len2; I ++) {carry = (F2 [I]-'0') + carry; char c = carry % 10 + '0'; carry/= 10; buff. push_back (c);} If (carry) buff. push_back ('1'); Return Buff;} void fill_fibs () {string F1, F2; f1.push _ back ('1'); f2.push _ back ('1 '); fibs. push_back (F1); fibs. push_back (F2); While (f2.length () <105) {string TMP = fig (F1, F2); F1 = F2; F2 = TMP; fig. push_back (F2);} fibs [0] = "0"; int size = fibs. size (); For (INT I = 0; I <size; I ++) reverse (FIBS [I]. begin (), fibs [I]. end ();} int main () {// freopen ("C: \ Users \ Asus \ Desktop \ cout.txt", "W", stdout ); // freopen ("C: \ Users \ Asus \ Desktop \ cout.txt", "W", stdout); fill_fibs (); string STA, en; while (CIN> sta> en, Sta [0]-'0' | En [0]-'0') {int I = 1, ANS = 0; while (1) {If (FIBS [I]. length ()> Sta. length () break; else if (FIBS [I]. length () = Sta. length () & fibs [I]> = Sta) break; I ++;} while (1) {If (FIBS [I] = EN) {ans ++; break;} If (FIBS [I]. length ()> en. length () break; else if (FIBS [I]. length () = en. length () & fibs [I]> en) break; I ++; ans ++;} cout <ans <Endl;} return 0 ;}

  

Number Theory: High Precision --- ultraviolet A 10183: How many fibs?

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.