Обработка математики: 100%

Module: Fast exponentiation


Problem

4/5

**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 
Fn+m=FmFn+1+Fm1Fn, write the recurrence relation for matrix product:
• if m=n then F2n=FnFn+1+Fn1Fn;
• if m=n+1 then F2n+1=Fn+1Fn+1+FnFn.
 

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<=1018).
 
Output
Print F(n) value, computed modulo 108.

Paste the missing code snippet into the program.

 

Examples
# Input Output
1 30 832040