Data Structures & AlgorithmsHardICPC regional · GATE CS
Problem: Compute 7^100 mod 13.
- A. 8
- B. 4
- C. 9
- D. 1
Correct answer: C. 9
Fermat gives 7¹² ≡ 1, and 100 ≡ 4 (mod 12), so 7⁴ = 2401 ≡ 9 (mod 13). Reducing the exponent mod 13 instead gives 7⁹ ≡ 8, 4 is just the reduced exponent, and 1 wrongly assumes 7¹⁰⁰ ≡ 1.
More Coding Interview Problems questions
- Problem: Using US coin denominations 1, 5, 10, 25, what is the minimum number of coins needed to make 63 (greedy works for these…
- Problem: Count the walks of length 3 on the path graph P4 (vertices 1–4, edges 1-2, 2-3, 3-4) that start and end at the same vertex. Walks…
- Problem: The array [2, 7, 4, 1, 8, 1] is examined by a sweep: for each index i, the value a[i] is compared with the minimum of the…
- Problem: Starting with the stack [1] (top is the rightmost element), the operations are: push 2, push 3, pop, push 4, push 5, pop, pop…
- Problem: A bank processes queued withdrawals of 40, 25, 60, 15, 30 from a balance of 100. Each withdrawal is processed only if the current…
- Problem: The Z-array of "aaabaab" is computed (z[0] is the full length by convention). What is the sum of z[1] through z[6]?