Data Structures & AlgorithmsVery hardICPC regional · number theory
Problem: Compute C(10, 3) mod 7 using Lucas' theorem, where 7 is prime. What is the result?
- A. 120
- B. 0
- C. 1
- D. 3
Correct answer: C. 1
In base 7, 10 = (1,3) and 3 = (0,3), so Lucas gives C(1,0) * C(3,3) = 1. Taking 120 mod 7 gives the same answer, while reading the digits without carry gives the trap.
More Coding Interview Problems questions
- Problem: What is 3^100 mod 10?
- Problem: How many positive divisors does 2^4 3^2 5 7 have?
- Problem: Minimum insertions of brackets to make the string '(()))(' valid, found by this greedy scan? python s = '(()))(' bal = 0 ins = 0…
- Problem: How many contiguous subarrays of [1, 2, 1, 2, 1, 3, 1] contain exactly 2 odd numbers? python a = [1, 2, 1, 2, 1, 3, 1] k = 2 cnt…
- Problem: How many subsets of {1, 2, 3, 4, 5, 6, 7, 8} have a sum of exactly 10? python cnt = 0 for m in range(1 << 8): if sum(i + 1 for i…
- Problem: After running Floyd-Warshall on a directed graph with possibly negative edges, which check correctly detects that vertex i lies…