You are viewing a single comment's thread. Return to all comments →
every even fibinoci number follows a pattern {2,8,34,144} if you look at 8 it is 2*4+0, 34 it is 8*4+2 , 144 it is 34*4+8
n = int(input().strip()) prev=0 i=2 s=0 tenp=0 while i<=n: s+=i temp=i i=i*4+prev prev=temp print(s)
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #2: Even Fibonacci numbers
You are viewing a single comment's thread. Return to all comments →
every even fibinoci number follows a pattern {2,8,34,144} if you look at 8 it is 2*4+0, 34 it is 8*4+2 , 144 it is 34*4+8
n = int(input().strip()) prev=0 i=2 s=0 tenp=0 while i<=n: s+=i temp=i i=i*4+prev prev=temp print(s)