Submission

Status:
-PPPP-----

Score: 40

User: exoworldgd

Problemset: อนุกรม

Language: cpp

Time: 0.002 second

Submitted On: 2024-12-14 21:18:28

#include <iostream>
using namespace std;
int main(void) {
    int n, a = 0, b = 1, fib;
    cin >> n;
    if (n == 1) {
        cout << 0;
        return 0;
    }
    if (n == 2) {
        cout << 1;
        return 0;
    }
    for (int i = 3; i <= n+1; i++) {
        fib = a + b;
        a = b;
        b = fib;
    }
    cout << b;
}