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
|
630 Discussions
|
Please Login in order to post a comment
KOTLIN Code
a very optimized solution with recursion
python def fib_sum_even(n, current, nextnum, sum_even): if current>n: return sum_even if current % 2 == 0: sum_even += current return fib_sum_even(n, nextnum, current+nextnum, sum_even)
include
include
using namespace std; int main(){ int n; cin >> n; for (int a = 0; a < n; a++){ long n; cin >> n;
}
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)