You are viewing a single comment's thread. Return to all comments →
C++ soln:
void sol(){ long long int n, ans = 2, i = 2; cin >> n; vector<long long int> dp; dp.push_back(1), dp.push_back(2); while(dp[i - 1] < n){ dp.push_back(dp[i - 1] + dp[i - 2]); if(dp[i]%2 == 0) ans += dp[i]; i++; } if(dp[i - 1]%2 == 0) ans -= dp[i - 1]; cout << ans << endl; } int main(){ int t; cin >> t; while(t--) sol(); return 0; }
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 →
C++ soln: