Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional

How many index pairs i < j of [2, 8, 3, 12, 6, 18] have a product that is a perfect square?

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

Correct answer: A. 4

A product is a square when every prime exponent is even; 2 and 8 give 16 and 2 and 18 give 36. Checking each of the 15 pairs with an integer square root gives the answer.

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

Exams that ask this topic