This page is still under construction.

Parts of this page are still being built. What you see may change.

Counting Fibonacci Numbers

Time limit1sMemory limit256 MB

Summary
For each query pair a and b up to 10^100, count how many Fibonacci numbers fall in the closed interval [a, b].
Level

Medium5 of 10

Topics
Math, Binary search, String, Brute force
Solved
No attempts yet

Problem

The Fibonacci numbers are defined as follows.

  • f1=1f_1 = 1
  • f2=2f_2 = 2
  • fn=fn−1+fn−2f_n = f_{n-1} + f_{n-2} (for n≥3n \ge 3)

Given two integers aa and bb, write a program that counts how many Fibonacci numbers lie in the interval [a,b][a, b]. In other words, count the Fibonacci numbers fif_i that satisfy a≤fi≤ba \le f_i \le b.

Input

The input consists of several test cases. Each test case is a single line containing two non-negative integers aa and bb separated by a space (a≤b≤10100a \le b \le 10^{100}). The two numbers are given without unnecessary leading zeros. The last line of the input contains two zeros, and this line is not processed.

Output

For each test case, print on its own line the number of Fibonacci numbers fif_i that satisfy a≤fi≤ba \le f_i \le b.

Examples1

  1. Example 1

    Input
    10 100
    1234567890 9876543210
    0 0
    
    Expected output
    5
    4