Sum of multiples of 3 or 5
Write code · Basic · §2.2 Divisors and multiples
Complete the function solution, which returns the sum of all the positive integers from 1 to n that are multiples of 3 or multiples of 5. n itself is included.
A number that is a multiple of both 3 and 5, such as 15, is added only once.
Function
solution(n)
Constraints
nis an integer from 1 to 1,000,000,000.
Examples
| n | result |
|---|---|
10 | 33 |
15 | 60 |
Starter code
def solution(n):
answer = 0
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.