Skip to content

Instantly share code, notes, and snippets.

@sifue
Created June 5, 2017 05:21
Show Gist options
  • Save sifue/0aaed427db4acd6cb4e1a73fbef358d6 to your computer and use it in GitHub Desktop.
Save sifue/0aaed427db4acd6cb4e1a73fbef358d6 to your computer and use it in GitHub Desktop.
プロジェクトオイラー問題2
#include <iostream>
using namespace std;
int main() {
int n2 = 0;
int n1 = 1;
int current = 2;
int sum = current;
// cout << n1 << endl;
// cout << current << endl;
while (current <= 4000000) {
n2 = n1;
n1 = current;
current = n2 + n1;
// cout << current << endl;
if (current % 2 == 0) {
sum = sum + current;
}
}
cout << sum << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment