#P3807. 【模板】卢卡斯定理 / Lucas 定理

    ID: 2752 远端评测题 1000ms 125MiB 尝试: 1 已通过: 1 难度: 7 上传者: 标签>递归素数判断,质数,筛法进制组合数学逆元Lucas 定理

【模板】卢卡斯定理 / Lucas 定理

Description

Given integers n,m,pn, m, p, compute Cn+mnmodpC_{n + m}^n \bmod p.

The input guarantees that pp is prime.

Note: CC denotes the binomial coefficient.

Input Format

This problem contains multiple test cases.

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

For each test case:

One line with three integers n,m,pn, m, p.

Output Format

For each test case, output one line with one integer, the required value.

2
1 2 5
2 1 5
3
3

Hint

For 100%100\% of the testdata, 1n,m,p1051 \leq n, m, p \leq 10^5, 1T101 \leq T \leq 10.

Translated by ChatGPT 5