Data Structures & AlgorithmsVery hardCodeforces Div2 B · GATE CS

What is the sum of gcd(a[i..j]) over all contiguous subarrays of [4, 6, 8, 12]?

  1. A. 46
  2. B. 40
  3. C. 44
  4. D. 88

Correct answer: C. 44

Single elements contribute themselves; for longer subarrays, the gcd of the whole run can be computed incrementally from the previous gcd for each start index.

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

Exams that ask this topic