Skip to main content
3 of 3
formatting
YCor
  • 63.9k
  • 5
  • 187
  • 286

For a given value of $n$ and $m$, find $\text{fib}(n)$ $\text{mod } m$ where $n$ is very huge. (Pisano Period)

Input

Integers $'n'$ (up to $10^{14}$) and $'m'$(up to $10^3$)

Output

$\text{Fib}(n)$ $\text{modulo}$ $m$

My questions

For example : Why $\text{fib}(n=2015)$ $\text{mod}$ $3$ is equivalent to $\text{fib}(7)$ $\text{mod } 3$? (for $𝑚 = 3$ the period is $01120221$ and has length $8$ and $2015=251*8 + 7$)

In general, after getting the remainder sequence, how (mathematical proof) it is used for computing $\text{Fib}(n)$ $\text{mod } m$?