Data Structures & AlgorithmsVery hardCodeforces Div2 B · ICPC regional

How many index pairs i < j make a[i] times a[j] a perfect square, for the array [2, 8, 18, 5, 12, 9, 50, 25, 32]?

  1. A. 10
  2. B. 22
  3. C. 31
  4. D. 11

Correct answer: D. 11

A product is a square exactly when the two square-free parts are equal. Parts: 2, 2, 2, 5, 3, 1, 2, 1, 2, so C(5,2) + C(2,2) = 11. Missing the (9, 25) pair gives 10, counting ordered pairs gives 22, and also pairing each element with itself gives 31.

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

Exams that ask this topic