Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many pairs (i, j) with 1 <= i < j <= 12 have a product i * j that is a perfect square?

  1. A. 6
  2. B. 17
  3. C. 5
  4. D. 12

Correct answer: C. 5

A product is a square when every prime exponent is even, which is a parity-vector check. Including i = j (the second option) adds the 12 squares of the diagonal.

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

Exams that ask this topic