ProgrammingVery hardCodeforces-style · placement coding round

What is printed?

What is printed?
M = 10**9 + 7
N = 10
fact = [1] * (N + 1)
for i in range(1, N + 1):
    fact[i] = fact[i - 1] * i % M
def nCr(n, r):
    return fact[n] * pow(fact[r] * fact[n - r], -1, M) % M
print(nCr(10, 3), nCr(10, 0), nCr(5, 5))
  1. A. 120 1 1
  2. B. 120 0 1
  3. C. 210 1 1
  4. D. 120 1 5

Correct answer: A. 120 1 1

Factorials are precomputed modulo M, and the inverse of a product comes from pow with exponent -1 (Python 3.8+). C(10, 3) is 120, while C(10, 0) and C(5, 5) are both 1.

More Python Programming questions

Exams that ask this topic