Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: cheeseycheese05
Problemset: อนุกรม
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-13 21:14:31
#include <iostream>
using namespace std;
long long fibonacci(int n){
if (n <= 0) return 0;
if (n <= 2) return 1;
long long a = 1; // F(1)
long long b = 1; // F(2)
long long c = 0; // F(n)
for (int i = 3; i <= n; i++) {
c = a + b;
a = b;
b = c;
}
return c;
}
int main(){
int n;
cin >> n;
cout << fibonacci(n);
return 0;
}