Project Euler's #1: Multiples of 3 and 5 DOUBT
So I was solving the Project Euler's first question which asks us to find the sum of all the multiples of 3 or 5 < given integer n
This is the code I wrote in python 3:
n = int(input().strip())
s=0
for i in range(n):
if i%3==0:
s=s+i
if i%5==0:
s=s+i
print(s)
This code works when the value of n is small, say 10. The sum comes out to be 23 i.e 3+5+6+9.
But if I put a larger value for n, say 100, then the code gives a wrong output. For n=100, the sum should be 2318 but I get 2633. I don't know how to solve this, I've tried everything that I know of. Please let me know how I solve this.