Alex_tz307

Fibonacci

Oct 26th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("text.in");
  7. ofstream fout("text.out");
  8.  
  9. int32_t main() {
  10.     int N, a = 0, b = 1;
  11.     fin >> N;
  12.     if(N == 0) {
  13.         fout << 0;
  14.         return 0;
  15.     }
  16.     if(N == 1) {
  17.         fout << 1;
  18.         return 0;
  19.     }
  20.     for(int i = 2; i <= N; ++i) {
  21.         int c = a + b;
  22.         a = b;
  23.         b = c;
  24.     }
  25.     fout << b;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment