#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 and , compute the sum of the first terms of the sequence modulo , i.e., .
Input Format
Input and .
Output Format
Output the sum of the first terms .
Sample 1
5 1000
12
Data Range and Hint
For of the data, , .