Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 B

How many pairs of distinct array positions i < j in [1, 2, 3, 4, 5, 6, 9] have a[i] * a[j] divisible by 6?

  1. A. 11
  2. B. 8
  3. C. 13
  4. D. 10

Correct answer: D. 10

A product is divisible by 6 when it contains both a factor 2 and a factor 3, so split the values by which of these divisors they contain and combine.

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

Exams that ask this topic