Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B
What is the sum of gcd(i, 12) over i = 1 to 12?
- A. 43
- B. 40
- C. 36
- D. 80
Correct answer: B. 40
Pillai's function is multiplicative: sum of gcd(i, n) over i = 1..n equals the sum over divisors d of n of d times phi(n/d). Computing it directly is fine at n = 12.
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
- Five customers arrive together at a bank with 2 tellers. Service times in arrival order are 3, 5, 2, 4 and 6 minutes. Each customer goes…
- A stack starts empty. Operations in order: push 1, push 2, pop, push 3, push 4, pop, pop. Write each popped value in order and read the…
- Buildings of heights 3, 7, 8, 3, 6, 1 stand in a row. A building is visible from the left if no building to its left is at least as tall…
- What is the length of the longest contiguous subarray of [4, 2, 4, 5, 6, 2, 4, 1] that contains no repeated value?
- How many contiguous subarrays of [4, 5, 0, -2, -3, 1] have a sum divisible by 4?
- How many distinct values v in the array [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] occur exactly v times?