Data Structures & AlgorithmsModerateICPC regional · GATE CS
Problem: Compute σ(360), the sum of all positive divisors of 360.
- A. 810
- B. 24
- C. 1170
- D. 540
Correct answer: C. 1170
360 = 2³ · 3² · 5 and σ is multiplicative: (1 + 2 + 4 + 8)(1 + 3 + 9)(1 + 5) = 15 · 13 · 6 = 1170. Excluding 360 itself gives 810, counting divisors gives 24, and multiplying (p^k + 1) terms (9 · 10 · 6) gives 540.
More Coding Interview Problems questions
- Problem: The gas-station problem: gas = [1, 2, 3, 4, 5] and cost = [3, 4, 5, 1, 2] around a circular route of 5 stations, starting with an…
- Problem: Children with greed factors g = [1, 2, 3] and cookies s = [1, 1] (each child takes at most one cookie, and a cookie of size ≥ the…
- Problem: Balloons are shot with arrows that burst every balloon whose horizontal interval contains the arrow's x position. Intervals are…
- Problem: A stream of integers arrives: 4, 9, 1, 7, 8, 3, 6. After each arrival from the 2nd onwards, we report the 2nd largest value seen…
- Problem: How many binary search trees can be formed with exactly 5 distinct keys?
- Problem: The quadratic residues modulo 8: how many integers x in 1 ≤ x ≤ 100 satisfy x² ≡ 1 (mod 8)?