Data Structures & AlgorithmsVery hardCodeforces Div 2 C · ICPC regional

Array [2, 8, 9, 18, 4, 16, 6, 3]. How many index pairs i < j have a[i] * a[j] equal to a perfect square?

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

Correct answer: D. 6

A product of two integers is a perfect square when they have the same squarefree part. Grouping values by squarefree part and adding C(group, 2) counts these pairs; the sum-based check is a different condition.

More Coding Interview Problems questions

Exams that ask this topic