Each Fibonacci number is the sum of the two numbers before it. This code builds the sequence up to four million and adds only the even numbers.
#include <iostream>
#include <vector>
using namespace std;
void solve(void) {
vector<int> f(33, 1);
for (int i=2; i<=32; i++) {
f[i] = f[i-1] + f[i-2];
}
int ans = 0;
for (int i=1; i<=32; i++) {
if (!(f[i] % 2)) ans += f[i];
}
cout << ans;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}