Fibonacci numbers (2) P74219


Statement
 

pdf   zip

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 problem://problemsjutge.org:problems/algorismia/divide-and-conquer/eleva-matriu.pbm.

Public test cases
  • Input

    0 100
    10 100
    10 9
    1000 876
    

    Output

    0
    55
    1
    411
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++