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))- A. 120 1 1
- B. 120 0 1
- C. 210 1 1
- 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
- What is printed? python def summin(a): MOD = 109 + 7 st = [] total = 0 cur = 0 for x in a: cnt = 1 while st and st[-1][0] >= x: v, c =…
- What is printed? python print(6 & 3 == 2, 5 | 2 == 7)
- What is printed? python import heapq def medians(xs): lo, hi = [], [] out = [] for x in xs: heapq.heappush(lo, -x) heapq.heappush(hi…
- What is printed? python def sieve(n): s = bytearray([1]) (n + 1) s[0:2] = bytes(2) for i in range(2, int(n 0.5) + 1): if s[i]: s[i i::i] =…
- What is printed? python a = [1, 2, 3] b = a b += [4] c = a + [5] a = a 2 print(b, c, a)
- What is printed? python def stepstocycle(f, s): seen = {} i = 0 while s not in seen: seen[s] = i s = f[s] i += 1 return i, i - seen[s]…