Data Structures & AlgorithmsModerateICPC regional · TCS NQT

Problem: The quadratic residues modulo 8: how many integers x in 1 ≤ x ≤ 100 satisfy x² ≡ 1 (mod 8)?

  1. A. 50
  2. B. 13
  3. C. 25
  4. D. 100

Correct answer: A. 50

Every odd square is 1 mod 8 (odd x = 2m + 1 gives 4m(m + 1) + 1, and m(m + 1) is even), so all 50 odd numbers qualify. Counting only x ≡ 1 (mod 8) gives 13, only x ≡ ±1 (mod 8) gives 25, and 100 forgets that even squares are 0 or 4 mod 8.

More Coding Interview Problems questions

Exams that ask this topic