You are viewing a single comment's thread. Return to all comments →
Passed all cases.....nice logic
C++
long long int n; cin>>n; long long int curr=0,prev=0,ans=0,next; curr=2; prev=0; ans=2; for(int i=1;i<=n;i++) { next=4*curr + prev; if(next>n) { cout<<ans<<endl; break; } ans=ans+next; prev=curr; curr=next; }
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Project Euler #2: Even Fibonacci numbers
You are viewing a single comment's thread. Return to all comments →
Passed all cases.....nice logic
C++