Coding


5
Aug 09

Project Euler – Problem 1

First of all what is ‘Project Euler’?

P.E. is a platform that is specifically aimed at students to provide them with mathematical/computer programming exercises. The idea behind all this is, that the coder have to understand the mathematics and the computer programming to solve the problems. One is dependent on the other. It’s very interesting and like a very small and harmless addiction. Tidy, short, elegant mathematical and coding solutions will be two of the positives effects of the P.E.

Problem

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.

Solution

import math

result = 0

for i in range (1,1000):
  if (i % 3 == 0 or i % 5 == 0):
    result += i

print("Sum: {0}".format(result))

Regards,

Prometheus