fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. int n;
  9. if (!(cin >> n)) return 0;
  10. if (n == 0 || n == 1) {
  11. cout << 1;
  12. return 0;
  13. }
  14.  
  15. int a = 1; // f(0)
  16. int b = 1; // f(1)
  17. for (int i = 2; i <= n; ++i) {
  18. int c = a + b; // f(i) = f(i-1) + f(i-2)
  19. a = b;
  20. b = c;
  21. }
  22. cout << b;
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty