fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. //Number of terms in the series having 0, 1.
  6. vector< long long > forward(2, 0), backward(2, 0);
  7. forward[1] = backward[1] = 1;
  8. long long MAX = 1e9;
  9. //Positive elements.
  10. while(forward.back() <= MAX){
  11. auto n = forward.size();
  12. auto next_element = forward[n-1] + forward[n-2];
  13. forward.push_back(next_element);
  14. }
  15. int count_elements = forward.size();
  16. //On the other side.
  17. while(abs(backward.back()) <= MAX){
  18. auto n = backward.size();
  19. auto next_element = backward[n-2] - backward[n-1];
  20. backward.push_back(next_element);
  21. }
  22. count_elements += backward.size() - 2;
  23. cout<<count_elements<<endl;
  24. return 0;
  25. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
90