Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 C

Problem: The value of 3^(3^3) mod 7 is what?

  1. A. 6
  2. B. 1
  3. C. 4
  4. D. 3

Correct answer: A. 6

3 has order 6 mod 7 and 27 ≡ 3 (mod 6), so 3²⁷ ≡ 3³ = 27 ≡ 6. Reducing the exponent mod 7 instead gives 3⁶ ≡ 1, computing 3 · 27 = 81 gives 4, and 3 is just the reduced exponent.

More Coding Interview Problems questions

Exams that ask this topic