Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

How many ordered pairs (i, j) with 1 <= i, j <= 20 have i^2 + j^2 divisible by 5?

  1. A. 148
  2. B. 136
  3. C. 144
  4. D. 156

Correct answer: C. 144

Squares are 0, 1 or 4 mod 5, and the only residue pairs summing to 0 mod 5 are (0,0), (1,4) and (4,1). Counting residue classes avoids enumerating pairs.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic