Problem · Math
Sum Multiples of 3, 5, or 7 Below N
Learn this problemProblem statement
Given a positive integer n, return the sum of all positive integers strictly less than n that are divisible by 3, 5, or 7.
Count an integer only once even when it is divisible by more than one of the three divisors.
Function
sumMultiples(n: int) → longExamples
Example 1
n = 12return = 40The included integers are 3, 5, 6, 7, 9, 10. Their sum is 40; 12 is excluded because the bound is strict.
Example 2
n = 16return = 81The included integers are 3, 5, 6, 7, 9, 10, 12, 14, 15. The value 15 is counted once even though both 3 and 5 divide it.
Example 3
n = 3return = 0No positive integer below 3 is divisible by 3, 5, or 7.
Constraints
1 <= n <= 10^9- The result fits in a signed 64-bit integer.
More Upstart problems
- Add Drama to Text GroupsOA · Seen Jul 2026
- Lexicographic Word FrequenciesOA · Seen Jul 2026
- Minimum Absolute Pair DifferenceOA · Seen Jul 2026
- Coordinate Bounding BoxOA · Seen Jul 2026
- Increase Exclamations and Convert PeriodsOA · Seen Jul 2026
- Interleave Equal-Length Strings by ColumnOA · Seen Jul 2026
- Scale Ingredient QuantitiesOA · Seen Jul 2026
- Bounding Box from CoordinatesOA · Seen May 2026