Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many contiguous subarrays of [6, 10, 15, 4] have gcd exactly 1?

  1. A. 5
  2. B. 3
  3. C. 6
  4. D. 4

Correct answer: D. 4

Once a subarray gcd reaches 1 every extension keeps 1, so the right end count for each start is easy to total. Brute force over the 10 subarrays confirms the count.

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

Exams that ask this topic