본문으로 바로가기

【Project Euler】Q1. Multiples

category Coding/Python 2020. 7. 14. 12:45

Question 1.

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6, 9.

The sum of these multiples is 23.

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

 

Answer

target = 1000

mult3or5 = []

for i in range(target):
    while i*3 < target and i*3 not in mult3or5:
        mult3or5.append(i*3)
    while i*5 < target and i*5 not in mult3or5:
        mult3or5.append(i*5)
    
print(sum(mult3or5))

 

Returns

233168