loading...
Cover image for Multiples of 3 and 5 - Project Euler Solution

Multiples of 3 and 5 - Project Euler Solution

codeperfectplus profile image CodePerfectPlus ・1 min read

Problem Solving Series(For Interview) (8 Part Series)

1) Multiples of 3 and 5 - Project Euler Solution 2) Two sum - Leet Code Solution 3 ... 6 3) Check for Armstrong Number 4) Largest palindrome product - Project Euler Solution 5) Smallest multiple - Project Euler Solution 6) Sum square difference - Project Euler Solution 7) 10001st prime - Project Euler Soution 8) Sieve of Eratosthenes

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))

Share Your Solutions for Multiples of 3 and 5?

Discussion

markdown guide