fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7.  
  8. long long a = 1, b = 1;
  9.  
  10. if (n == 0 || n == 1) {
  11. cout << 1;
  12. return 0;
  13. }
  14.  
  15. for (int i = 2; i <= n; i++) {
  16. long long c = a + b;
  17. a = b;
  18. b = c;
  19. }
  20.  
  21. cout << b;
  22. }
Success #stdin #stdout 0.01s 5292KB
stdin
4
stdout
5