题意:
求斐波那契数列中,小于四百万的 前n项 偶数值的和
解题思路:
简单模拟....
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
int main() {
int f1 = 1;
int f2 = 2;
int f3 = 0, ans = 2;
while(f3 < 4000000) {
f3 = f1 + f2;
f1 = f2;
f2 = f3;
if(f3 % 2 == 0) {
ans += f3;
}
}
cout << ans << endl;
return 0;
}
Answer: 4613732