Sometimes N is often used when calculating the number of combinations! If n is less than or equal to 1e5, it can be preprocessed by O (N). Of course, the MOD is usually 1e9 + 7.
The code is not hard to write:
FAC [0] = 1;
For (INT I = 1; I <= N; I ++) FAC [I] = (FAC [I-1] * I) % MOD;
Inv [N] = pow_mod (FAC [N], mod-2); // FAC [N] ^ {mod-2}
For (INT I = n-1; I> = 0; I --) inv [I] = inv [I + 1] * (I + 1) % MOD;
Then directly return FAC [N] * inv [m] % mod * inv [N-M] % MOD; // calculate C (n, m), be sure not to overflow
If mod is smaller than N, pay attention to it, because if inv [I + 1] = 0, it will lead to 0 in the front, and although it has not been studied in depth, however, in this case, the effect is not very good,
Therefore, this preprocessing is only used on MOD 1e9 + 7 or 1e9 + 9. (Just me)
Factorial inverse metaline push (Consolidation + optimization)