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)?

  1. A. 499122176
  2. B. 499122177
  3. C. 998244352
  4. 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

Exams that ask this topic