Skip to content

Instantly share code, notes, and snippets.

@Buzz-Lightyear
Created November 5, 2014 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Buzz-Lightyear/540d0fe66e966141a5b5 to your computer and use it in GitHub Desktop.
Save Buzz-Lightyear/540d0fe66e966141a5b5 to your computer and use it in GitHub Desktop.
Project Euler Problem 2 - Sum of Even Fibonacci numbers below 4 million
#include <iostream>
#include "stdint.h"
using namespace std;
int main() {
uint64_t sumOfEvenValues = 2;
for(uint64_t a = 1, b = 2, term = 0;;)
{
term = a + b;
a = b;
b = term;
term = a + b;
a = b;
b = term;
if(term <= 4000000LL)
{
term = a + b;
sumOfEvenValues += term;
a = b;
b = term;
}
else
break;
}
cout << sumOfEvenValues << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment