Module: The Euler function and other problems in number theory


Problem

9/9

**Fibonacci numbers modulo (C++)

Theory Click to read/hide

Modulo Fibonacci numbers

To efficiently find the Fibonacci number, we use matrix multiplication, more details here.
 
Knowing that 
\(F_{n+m} = F_m F_{n+1} + F_{m-1} F_n\), write the recurrence relation for matrix product:
• if \(m = n\) then \(F_{2n} = F_n F_{n+1} + F_ {n-1} F_n\);
• if \(m = n + 1\) then \(F_{2n+1} = F_{n+1 } F_{n+1} + F_n F_n\).
 

Problem

As you know, the Fibonacci sequence is defined as follows:
\(F(0) = 0,\ F(1) = 1,\ F(n) = F(n – 1) + F(n – 2)\ ), for all \(n > 1\).
It is named after the Italian mathematician Leonardo Fibonacci, also known as Leonardo of Pisa.
 
Input
The string contains an integer n (\(1 <= n <= 10^{18}\)).
 
Output
Print F(n) value, computed modulo \(10^8\).

Paste the missing code snippet into the program.

 

Examples
# Input Output
1 30 832040