#P10664. BZOJ3328 PYXFIB

    ID: 12164 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>原根数论O2优化矩阵乘法单位根反演

BZOJ3328 PYXFIB

Problem Description

Given integers n,k,pn, k, p, compute the value of the following expression modulo pp:

$$\sum_{i=0}^{\lfloor \frac{n}{k} \rfloor} C_n^{i\times k}\times F_{i\times k}$$

Where:

  • pp is a prime number, and the remainder of pp divided by kk is 11.
  • CC denotes the binomial coefficient, i.e. Cnm=n!m!(nm)!C_n^m=\frac{n!}{m!(n-m)!}.
  • FnF_n denotes the Fibonacci sequence, i.e. F0=1F_0=1, F1=1F_1=1, Fn=Fn1+Fn2(n2)F_n=F_{n-1}+F_{n-2}(n\geq 2).

Input Format

The first line contains a positive integer TT, the number of test cases.

The next TT lines each contain three positive integers n,k,pn, k, p.

Output Format

Output TT lines, each containing one integer, which is the result.

1
1 2 3
1

Hint

For 100%100\% of the testdata, it is guaranteed that 1n10181\leq n\leq 10^{18}, 1k200001\leq k \leq 20000, 1T201\leq T\leq 20, 1p1091\leq p\leq 10^9, pp is a prime number, and the remainder of pp divided by kk is 11.

Translated by ChatGPT 5