Data Structures & AlgorithmsHardTCS NQT · ICPC regional

Problem: Count the pairs (i, j) with 1 ≤ i < j ≤ 12 for which the number i·j is a perfect square.

  1. A. 6
  2. B. 4
  3. C. 5
  4. D. 7

Correct answer: C. 5

Test each pair's product for being a perfect square with isqrt. Checking whether i and j are themselves squares misses pairs such as (2, 8) whose product is 16.

More Coding Interview Problems questions

Exams that ask this topic