#Q223. 「一本通 6.5 例 3」Fibonacci 前 n 项和

「一本通 6.5 例 3」Fibonacci 前 n 项和

Description

Everyone knows the Fibonacci sequence, right? $f_1=1, f_2=1, f_3=2, f_4=3, \dots, f_n=f_{n-1}+f_{n-2}$.

Now the problem is simple: given nn and mm, compute the sum of the first nn terms of the sequence {fn}\{f_n\} modulo mm, i.e., SnmodmS_n \bmod m.

Input Format

Input nn and mm.

Output Format

Output the sum of the first nn terms SnmodmS_n \bmod m.

Sample 1

5 1000

12

Data Range and Hint

For 100%100\% of the data, 1n2×1091 \le n \le 2 \times 10^9, 1m109+101 \le m \le 10^9 + 10.