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