Problem 117589 · easy · Phase 01 Prerequisites & Setup

Sum of the Multiples

functions · loops · modulo

Write sum_of_multiples(a, b, limit) that returns the sum of all positive integers below limit that are divisible by a or by b (or both). Count each number once.

Examples

Input:  a = 3, b = 5, limit = 10
Output: 23
Explanation: 3 + 5 + 6 + 9 = 23.

Input:  a = 2, b = 4, limit = 10
Output: 20

Input:  a = 3, b = 5, limit = 1
Output: 0

Constraints

  • 1 <= a, b <= 1000
  • 0 <= limit <= 2 * 10**5

Goals

  • Combine two divisibility tests with `or`
  • Accumulate a sum over a range
Starting Python…