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]?
- A. 46
- B. 40
- C. 44
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many index pairs i < j have gcd(a[i], a[j]) = 1 for the array [2, 3, 4, 5, 6, 9]?
- What is the sum of lcm(a[i], a[i+1]) for consecutive pairs of the array [2, 3, 4, 6, 9]?
- How many integers x in the range 1 to 1000 are divisible by 3 and have a digit sum divisible by 7?
- How many contiguous subarrays of [3, 4, 1, 2, 5, 6] have a sum divisible by 5?
- How many pairs i < j with 1 <= i, j <= 12 have i times j divisible by 12?
- What is the value of the sum of floor(20 / i) for i = 1 to 20?