#Q224. 「一本通 6.5 例 4」佳佳的 Fibonacci

「一本通 6.5 例 4」佳佳的 Fibonacci

Description

Jiajia is very interested in mathematics, especially in sequences. After studying the Fibonacci sequence, she has created many peculiar sequences. For example, let S(n)S(n) denote the sum of the first nn terms of the Fibonacci sequence modulo mm, i.e., S(n)=(F1+F2+...+Fn)modmS(n)=(F_1+F_2+...+F_n)\bmod m, where F1=F2=1F_1=F_2=1 and Fi=Fi1+Fi2F_i=F_{i-1}+F_{i-2}. However, this is still a piece of cake for Jiajia.

Finally, she encountered a problem she couldn't solve. Let T(n)=(F1+2F2+3F3+...+nFn)modmT(n)=(F_1+2F_2+3F_3+...+nF_n)\bmod m represent the modified sum of the first nn terms of the Fibonacci sequence modulo mm.

Now, Jiajia gives you two integers nn and mm, and asks you to compute the value of T(n)T(n).

Input Format

The input consists of a single line containing two integers nn and mm, separated by a space.

Output Format

Output a single line containing the value of T(n)T(n).

Sample 1

$T(5)=(1+2\times 1+3\times 2+4\times 3+5\times 5)\bmod 5=1$

5 5

1

Constraints and Hints

For 30%30\% of the data, 1n10001\le n \le 1000;

For 60%60\% of the data, 1m10001\le m \le 1000;

For 100%100\% of the data, 1n,m23111\le n,m \le 2^{31}-1.