# public dhruvbaldawa /project_euler

### Subversion checkout URL

You can clone with HTTPS or Subversion.

 ``` b299bcb5 » dhruvbaldawa ``` 2011-12-30 Solved the problem 2 1 """ 2 Problem 1 3 Add all the natural numbers below one thousand that are multiples of 3 or 5. 4 5 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. 6 Find the sum of all the multiples of 3 or 5 below 1000. 7 """ ``` ec7e701b » dhruvbaldawa ``` 2011-12-30 Added alternative solution to problem 1 8 def bruteforce(): 9 sum_ = 0 10 number = 1000 11 12 # Iterate over all the numbers and add those satisfy the condition 13 for x in range(1, number): 14 if x % 3 == 0 or x % 5 == 0: 15 sum_ = sum_ + x 16 print sum_ 17 18 def divisibility(): 19 sum_ = 0 20 number = 1000 21 22 # Find the numbers divisible by 3 23 l = range(1, number) 24 number_three = len(l) / 3 25 # This is basically sum(1..n) = n*(n+1)/2 26 sum_three = number_three * (number_three + 1)/2 27 28 # Find the numbers divisible by 5 29 number_five = len(l) / 5 30 # This is basically sum(1..n) = n*(n+1)/2 31 sum_five = number_five * (number_five + 1)/2 32 33 # Find the number of numbers divisible by 15 34 number_fifteen = len(l) / 15 35 # This is basically sum(1..n) = n*(n+1)/2 36 sum_fifteen = number_fifteen * (number_fifteen + 1)/2 37 38 sum_ = 3 * sum_three + 5 * sum_five - 15 * sum_fifteen 39 print sum_ 40 41 bruteforce() 42 divisibility()