Catalan number modulo prime

Write codeHard30 minCitadel style

Your task

Compute the n-th Catalan number modulo a prime p, where C_n = (2n choose n) / (n + 1). Use factorials and modular inverses (Fermat) so the division by (n+1) is done mod p. Constraints: 0 <= n <= 100000, p is a prime up to 10^9+7 with p > n+1. Return C_n mod p. C_0 = 1.

Examples

catalan_mod_p(n: int, p: int) -> int
Example 1
Inputcatalan_mod_p(3, 1000000007)
Output5