Data Structures & AlgorithmsHardGATE CS · ICPC regional

How many ordered pairs (a, b) with 1 <= a, b <= 30 satisfy a^2 + b^2 divisible by 7?

  1. A. 17
  2. B. 16
  3. C. 14
  4. D. 20

Correct answer: B. 16

Each a contributes only its square residue mod 7 (0, 1, 2 or 4), so group the values 1 to 30 by that residue and count the compatible pairs of classes whose residues sum to 0 mod 7.

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

Exams that ask this topic