Fibonacci numbers (2)

For every given pair of natural numbers nn and mm, compute FnmodmF_n \bmod m, where FnF_n is the nn-th Fibonacci number (starting at 0).

Input

The input consists of several pairs of nn and mm. Assume 0n1090 \le n \le 10^9 and 2m1032 \le m \le 10^3.

Output

For every given pair, print FnmodmF_n \bmod m.

Hint

Consider the problem P61833.

Problem information

Author: Salvador Roura

Generation: 2026-03-10T19:46:25.995Z

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