I was solving the Project Euler problem 2
*By starting with 1 and 2, the first 10 terms of Fibonacci Series will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Find the sum of all the even-valued terms in the sequence which do not exceed 4 million.*
here is my code in Python
a=0 b=1 nums = [] while True: x=a+b a=b b=x if(b>4000000): break nums.append(x) sum=0 for x in nums: if(x%2==0): sum+=x print sum
I noticed that the answer comes out to be 4613732 However I initially did a mistake by doing x%2!=0 and the answer turned out to be 4613731 (4613732-1) Is this some property or just luck??