Extended Fibonacci numbers P25832


Statement
 

pdf   zip

The well known Fibonacci numbers are defined recursively as follows: F0=0F_0 = 0, F1=1F_1 = 1, Fi=Fi1+Fi2F_i = F_{i-1} + F_{i-2} for i2i \ge 2. The first Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, ….

Let us generalize the Fibonacci numbers. For every pair of natural numbers aa and bb, define the sequence S(a,b)=[f0,f1,]S(a, b) = [f_0, f_1, \dots] as f0=af_0 = a, f1=bf_1 = b, fi=fi1+fi2f_i = f_{i-1} + f_{i-2} for i2i \ge 2. Note that S(0,1)S(0, 1) is the traditional Fibonacci sequence.

You are given a natural number nn. Please compute how many pairs (a,b)(a, b) exist such that S(a,b)S(a, b) has a i3i \ge 3 where fi=nf_i = n. For instance, for n=2n = 2 there are exactly three such sequences: S(0,1)=[0,1,1,2,]S(0, 1) = [0, 1, 1, 2, \dots], S(1,0)=[1,0,1,1,2,]S(1, 0) = [1, 0, 1, 1, 2, \dots], and S(2,0)=[2,0,2,2,]S(2, 0) = [2, 0, 2, 2, \dots].

Input

Input consists of several cases, each with a different natural number nn between 1 and 10610^6.

Output

For every nn, print the number of pairs (a,b)(a, b) such that nn appears at a position i3i \ge 3 in S(a,b)S(a, b).

Hint

Depending on your solution, Cassini’s identity could be useful: Fi1Fi+1Fi2=(1)iF_{i-1} \cdot F_{i+1} - F_i^2 = (-1)^i.

Public test cases
  • Input

    2
    1
    3
    9
    10
    1000
    1000000
    

    Output

    3
    1
    4
    8
    10
    780
    773883
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++