Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many index pairs i < j have gcd(a[i], a[j]) = 1 for the array [2, 3, 4, 5, 6, 9]?

  1. A. 10
  2. B. 8
  3. C. 12
  4. D. 9

Correct answer: D. 9

Count all pairs first (there are 15) and then subtract pairs sharing a prime factor. Using inclusion-exclusion over prime divisors avoids checking each pair.

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

Exams that ask this topic