Data Structures & AlgorithmsHardICPC regional · GATE CS

Problem: Compute 7^100 mod 13.

  1. A. 8
  2. B. 4
  3. C. 9
  4. D. 1

Correct answer: C. 9

Fermat gives 7¹² ≡ 1, and 100 ≡ 4 (mod 12), so 7⁴ = 2401 ≡ 9 (mod 13). Reducing the exponent mod 13 instead gives 7⁹ ≡ 8, 4 is just the reduced exponent, and 1 wrongly assumes 7¹⁰⁰ ≡ 1.

More Coding Interview Problems questions

Exams that ask this topic