Data Structures & AlgorithmsHardICPC regional · GATE CS

Problem: Calculate the number of ordered pairs (x, y) of integers with 1 ≤ x, y ≤ 20 for which x² + y² is divisible by 5.

  1. A. 74
  2. B. 16
  3. C. 80
  4. D. 144

Correct answer: D. 144

Squares mod 5 are 0, 1, 4; pairs with both ≡ 0 (4 × 4 = 16) or residues {1, 4} (2 × 8 × 8 = 128) give 144. Unordered pairs give 74, both multiples of 5 gives only 16, and one fifth of 400 is 80.

More Coding Interview Problems questions

Exams that ask this topic