Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 B

How many index pairs i < j in the array [1, 2, 3, 4, 5, 6] satisfy gcd(a[i], a[j]) = 1 and a[i] + a[j] is odd?

  1. A. 9
  2. B. 8
  3. C. 15
  4. D. 11

Correct answer: B. 8

An odd sum needs one odd and one even element: 3 × 3 = 9 pairs, and (3, 6) is the only one with gcd > 1, leaving 8. Ignoring the gcd gives 9, ignoring the parity gives the 11 coprime pairs, and 15 counts all pairs.

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

Exams that ask this topic