luogu#P4720. 【模板】扩展卢卡斯定理 / exLucas

【模板】扩展卢卡斯定理 / exLucas

Background

This is a template problem.

Problem Description

Compute

Cnmmodp{\mathrm{C}}_n^m \bmod{p}

where C\mathrm{C} is the binomial coefficient.

Input Format

One line with three integers n,m,pn, m, p, with meanings as described in the statement.

Output Format

Output one integer in one line, representing the answer.

5 3 3
1
666 233 123456
61728

Hint

For 100%100\% of the testdata, 1mn10181 \le m \le n \le {10}^{18}, 2p1062 \le p \le {10}^6, and it is not guaranteed that pp is a prime number.

Translated by ChatGPT 5