ProgrammingVery hardTCS NQT · Accenture
Compute C(10, 3) modulo 7 using Pascal's rule C(n, k) = C(n-1, k-1) + C(n-1, k), reducing every entry mod 7. What is printed?
Compute C(10, 3) modulo 7 using Pascal's rule C(n, k) = C(n-1, k-1) + C(n-1, k), reducing every entry mod 7. What is printed?
build the table C[n][k] for 0 <= k <= n <= 10 with C[n][0] = C[n][n] = 1 C[n][k] = (C[n-1][k-1] + C[n-1][k]) mod 7 Print C[10][3]
- A. 120
- B. 1
- C. 0
- D. 3
Correct answer: B. 1
C(10,3) = 120 and 120 mod 7 = 1. Forgetting the reduction gives 120, reading the wrong column C(10,4) gives 210 mod 7 = 0, and C(10,2) = 45 gives 3.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- By Fermat's little theorem, for a prime p and a not divisible by p, the inverse of a is a^(p-2) mod p. The procedure below finds the…
- A pair (a, b) with 1 <= a < b <= 20 is called coprime if gcd(a, b) = 1. The procedure below counts coprime pairs. What is printed? count =…
- The sum of the divisors of N = 28 is computed by the procedure below. A number is perfect when its proper divisors (excluding N) add up to…
- The procedure below counts the digits of 2^10 by repeated division by 10. What is printed? N = 2^10; d = 0 while N > 0 N = N div 10; d = d…
- Euclid's algorithm finds gcd(48, 18) by replacing the pair (a, b) with (b, a mod b) until b is 0. The loop below counts how many times the…
- The number of ordered pairs (x, y) of positive integers with x y = 36 is counted by the procedure below. What is printed? count = 0 for x…