Problem 117589 · easy · Level 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 = 4, b = 6, limit = 14
Output: 30
Explanation: 4 + 6 + 8 + 12 = 30; 12 is a multiple of both but counts once.

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…