DEV Community

Cover image for Multiples of 3 and 5 - Project Euler Solution
Deepak Raj
Deepak Raj

Posted on • Edited on • Originally published at codeperfectplus.com

5 2

Multiples of 3 and 5 - Project Euler Solution

Multiples of 3 and 5 - Project Euler Solution

Topic : Multiples of 3 and 5

Problem Statement:

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

You can find the original question here -> Project Euler

Multiples of 3 and 5 in python

def multiples(n):
    sum = 0
    for i in range(n):
        if(i%3==0) or (i%5==0):
            sum += i
    return sum

print(multiples(1000))
Enter fullscreen mode Exit fullscreen mode

Share Your Solutions for Multiples of 3 and 5?

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay