SHARE
TWEET

2 D

kot_mapku3 Jun 2nd, 2020 526 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7.     ios::sync_with_stdio(false);
  8.     cin.tie(nullptr);
  9.  
  10.     long long n;
  11.     cin >> n;
  12.     vector<long long> v(2);
  13.     v[0] = 0; v[1] = 1;
  14.  
  15.     if (n == 0) cout << 0;
  16.     else if (n == 1) cout << 1;
  17.     else {
  18.         int it = 2;
  19.         while (v.back() < n) {
  20.             v.push_back(v[it - 1] + v[it - 2]);
  21.             it++;
  22.         }
  23.  
  24.         if (v.back() == n) cout << it - 1;
  25.         else cout << -1;
  26.     }
  27.  
  28.     return 0;
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top