Fibonacci numbers (2)

For every given pair of natural numbers n and m, compute F_(n) mod  m,
where F_(n) is the n-th Fibonacci number (starting at 0).

Input

The input consists of several pairs of n and m. Assume 0 ≤ n ≤ 10⁹ and
2 ≤ m ≤ 10³.

Output

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

Hint

Consider the
problem problem://problemsjutge.org:problems/algorismia/divide-and-conquer/eleva-matriu.pbm.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:46:25.698Z

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