Data Structures & AlgorithmsHardCodeforces Div2 C · modular arithmetic
Problem: Modulo the prime p = 998244353, which value is the multiplicative inverse of 2, i.e. the x in [0, p) with 2x ≡ 1 (mod p)?
- A. 499122176
- B. 499122177
- C. 998244352
- D. 332748118
Correct answer: B. 499122177
Since 2 * 499122177 = 998244354 = p + 1, the inverse is (p + 1) / 2 = 499122177. The value 332748118 is the inverse of 3, a trap from mixing up the divisor.
More Coding Interview Problems questions
- Problem: A product of 11 matrices A1 A2 ... A11 is evaluated by choosing a full parenthesisation. How many different parenthesisations are…
- Problem: n = 10 people stand in a circle and every 3rd person is removed until one remains (counting starts at person 1 and the removed…
- Problem: Compute F(100) mod 1000 where F(0) = 0, F(1) = 1 and F(n) = F(n-1) + F(n-2). python def mul(A, B, m): return [[sum(A[i][k]…
- Problem: Count the inversions of the array [3, 1, 4, 1, 5, 9, 2, 6], where an inversion is a pair of positions i < j with a[i] > a[j]…
- Problem: Huffman coding is applied to symbol frequencies 5, 9, 12, 13, 16, 45, always merging the two smallest weights. What is the total…
- Problem: Find the maximum of every window of size 3 in the array below, printing the list of window maxima. python from collections import…