Advertisement
ranisalt

Euler 2

Aug 18th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. static void fib(std::vector<unsigned int> &v) {
  5.     unsigned int x = 1, y = 2;
  6.     do {
  7.         if (!(x & 1))
  8.             v.push_back(x);
  9.         y = x + y;
  10.         x = y - x;
  11.     } while (x < 4000000);
  12. }
  13.  
  14. int main() {
  15.     unsigned int anitta = 0;
  16.     std::vector<unsigned int> v;
  17.     fib(v);
  18.     for (unsigned short i = 0; i < v.size(); ++i)
  19.         anitta += v.at(i);
  20.     std::cout << anitta << '\n';
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement