Sum Multiples of 3, 5, or 7
Problem statement
Given a positive integer n, return the sum of all positive integers from 1 through n, inclusive, that are divisible by 3, 5, or 7.
Count a number only once even when more than one of those divisors divides it.
Function
sumMultiples(n: int) → longExamples
Example 1
n = 7return = 21The included values are 3, 5, 6, 7, whose sum is 21.
Example 2
n = 10return = 40The included values are 3, 5, 6, 7, 9, 10. Each value is counted once.
Example 3
n = 1return = 0No value in the inclusive range is divisible by 3, 5, or 7.
Constraints
1 <= n <= 10^9.- The result fits in a signed 64-bit integer.