Given a positive integer n, find the sum of all integers in the range [1, n] that are divisible by 3, 5, or 7.
Return that sum.
Example 1:
Input: {"n":7}
Output: 21
Constraints:
1≤n≤103
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":7}
f(k) sums the multiples of k up to 7: k + 2k + ... + mk = k * m(m + 1) / 2 with m = n // k. Adding f(3), f(5), f(7) alone would count shared multiples twice.