Problem 2
フィボナッチさん懐かしいねー
#include <iostream> #include <vector> using namespace std; #define LIMIT 4000000 int main(int argc, char **argv) { vector<int> vf; // フィボナッチ数列 vf.push_back(1); vf.push_back(2); while (1) { vector<int>::size_type e = vf.size(); vf.push_back(vf.at(e-2) + vf.at(e-1)); if (vf.at(e) > LIMIT) { break; } } int sum = 0; for (vector<int>::size_type i = 1, end = vf.size(); i < end; i+=3) { sum += vf.at(i); } cout << sum << endl; return 0; }