PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CT00047. Số Fibonacci (Fibonacci Numbers)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Số Fibonacci (Fibonacci Numbers)

Fibonacci Numbers

Version: Phuoc Hung OJ Extended

Problem Statement

The Fibonacci sequence is defined by F0=0F_0=0, F1=1F_1=1, and Fi=Fi−1+Fi−2F_i=F_{i-1}+F_{i-2} for i≥2i\ge2. A positive integer xx is a Fibonacci number if x=Fix=F_i for some index ii. Count each distinct value only once; in particular, 11 is counted once even though F1=F2=1F_1=F_2=1.

Given positive integers L,RL,R with L≤RL\le R, count the Fibonacci values in the inclusive interval [L,R][L,R].

Input

One line contains the positive integers L,RL,R.

Output

Print one integer: the number of distinct Fibonacci values in [L,R][L,R].

Subtasks

  • Subtask 1 (40 points): 1≤L≤R≤1061\le L\le R\le10^6.
  • Subtask 2 (30 points): 1≤L≤R≤10121\le L\le R\le10^{12}.
  • Subtask 3 (30 points): 1≤L≤R≤10181\le L\le R\le10^{18}.

Examples

Example 1

Input

1 20

Output

6

Explanation

The distinct positive Fibonacci values up to 2020 are 1,2,3,5,8,131,2,3,5,8,13. The next value, 2121, exceeds the upper endpoint. All six values are in the interval.

Example 2

Input

10 100

Output

5

Explanation

The values below 1010 are 1,2,3,5,81,2,3,5,8 and do not count. The values in the requested range are 13,21,34,55,8913,21,34,55,89, followed by 144>100144>100, so there are five.

Example 3

Input

100 1000

Output

5

Explanation

The in-range Fibonacci values are 144,233,377,610,987144,233,377,610,987. Their predecessor 8989 is below the interval and the successor 15971597 is above it, giving five values.