Data Structures & AlgorithmsHardCodeforces Div2 B · modular arithmetic

Problem: What is 7^222 mod 10? Run the code.

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

Correct answer: D. 9

The last digit of powers of 7 cycles 7, 9, 3, 1 with period 4. Since 222 mod 4 = 2, the result is 9.

More Coding Interview Problems questions

Exams that ask this topic