Data Structures & AlgorithmsModerateCodeforces Div2 B · modular arithmetic

Problem: What is 2^100 mod 7? Run the code.

Problem: What is 2^100 mod 7? Run the code.
print(pow(2, 100, 7))
What is printed?
  1. A. 1
  2. B. 4
  3. C. 2
  4. D. 3

Correct answer: C. 2

2^3 = 8 ≡ 1 (mod 7), and 100 = 3 * 33 + 1, so 2^100 ≡ 2^1 = 2.

More Coding Interview Problems questions

Exams that ask this topic