Data Structures & AlgorithmsHard

How many index pairs i < j in 1 2 4 8 9 3 12 6 have a product A[i]·A[j] that is a perfect square?

  1. A. 13
  2. B. 4
  3. C. 5
  4. D. 19

Correct answer: C. 5

A product is a square exactly when every prime appears to an even power across both factors; the pair test uses the product directly. Including the diagonal, testing the sum, or a divisibility shortcut each answer a different question.

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

Exams that ask this topic