Problems > Binomial Coefficient > Editorial

Binomial Coefficient — Solution & Editorial

Back to the Problem

Precompute factorials mod p; C(n,k) = n! · (k!)−1 · ((n−k)!)−1 with Fermat inverses.

Complexity: O(N) precompute, O(log p) per query