Fibonacci numbers (1)

The Fibonacci numbers F_(n) are defined as follows:
$$F_n = \left\{
\begin{array}{ll}
0 & \mbox{if $n = 0$} \\
1 & \mbox{if $n = 1$} \\
F_{n-1} + F_{n-2} & \mbox{if $n \ge 2$}
\end{array}
\right.$$
Therefore, the first Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21,
34, 55, …

For every given pair of natural numbers n and m, compute F_(n) mod  m.

Input

Input consists of several pairs of n and m. Assume 0 ≤ n ≤ 1000 and
2 ≤ m ≤ 10⁸.

Output

For every given pair, print F_(n) mod  m.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T10:13:23.133Z

© Jutge.org, 2006–2026.
https://jutge.org
