Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 B

For the array [1, 2, 3, 4, 6, 12], how many index pairs i < j have a[j] divisible by a[i]?

  1. A. 14
  2. B. 9
  3. C. 12
  4. D. 17

Correct answer: C. 12

The divisibility is from the earlier element to the later one, so the pair is counted in only one direction. Counting both directions doubles the answer.

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

Exams that ask this topic