We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Project Euler #2: Even Fibonacci numbers
Project Euler #2: Even Fibonacci numbers
Sort by
recency
|
626 Discussions
|
Please Login in order to post a comment
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)
couple hints: 1. don't compute all fibonacci numbers, the even ones are sufficient 2. store a fine selection of even fibonacci numbers and their pre sums for later reference 3. you can even speed up the search for the matching even fibonacci number by using a matching exponential factor and some log functions
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
}
Easier than #1