#P4000. 斐波那契数列

    ID: 2931 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串数学O2优化素数判断,质数,筛法斐波那契,Fibonacci

斐波那契数列

Description

Everyone knows the Fibonacci sequence is defined by the following properties:

  • f0=0f_0 = 0.
  • f1=1f_1 = 1.
  • fn=fn1+fn2f_n = f_{n-1} + f_{n-2} (n2n \geq 2 and nn is an integer).

Please compute the value of fnmodpf_n \bmod p.

Input Format

  • Line 1: An integer nn.
  • Line 2: An integer pp.

Output Format

  • Line 1: The value of fnmodpf_n \bmod p.
5
1000000007
5
10
1000000007
55

Hint

For 100%100\% of the testdata, 0n10300000000 \leq n \leq 10^{30000000}, 1p<2311 \leq p < 2^{31}.

Translated by ChatGPT 5