Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

How many unordered pairs {a, b} with a < b and 1 <= a, b <= 30 have a * b a perfect square?

  1. A. 19
  2. B. 20
  3. C. 21
  4. D. 23

Correct answer: A. 19

A product is a square exactly when the square-free parts of a and b coincide. Grouping the numbers by square-free part counts the pairs directly.

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

Exams that ask this topic