Data Structures & AlgorithmsHardCodeforces Div2 C · combinatorics

Problem: What is C(20, 10) mod 1000? Compute it with Pascal's triangle reduced mod 1000. Run the code.

Problem: What is C(20, 10) mod 1000? Compute it with Pascal's triangle reduced mod 1000. Run the code.
n, k = 20, 10
C = [[0] * (k + 1) for _ in range(n + 1)]
for i in range(n + 1):
    C[i][0] = 1
    for j in range(1, min(i, k) + 1):
        C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000
print(C[n][k])
What is printed?
  1. A. 756
  2. B. 184
  3. C. 856
  4. D. 656

Correct answer: A. 756

C(20, 10) = 184756, and 184756 mod 1000 = 756. Reducing modulo 1000 at each Pascal step keeps numbers small without changing the answer.

More Coding Interview Problems questions

Exams that ask this topic