Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: loop
Problemset: อนุกรม
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-10 18:29:43
#include <iostream>
#include <string>
using namespace std;
// F(100) has 21 digits, more than unsigned long long holds, so add decimal strings.
string add(const string &a, const string &b) {
string r = "";
int i = (int)a.size() - 1, j = (int)b.size() - 1, carry = 0;
while (i >= 0 || j >= 0 || carry) {
int d = carry;
if (i >= 0) d += a[i--] - '0';
if (j >= 0) d += b[j--] - '0';
r = char('0' + d % 10) + r;
carry = d / 10;
}
return r;
}
int main() {
int n;
cin >> n;
string a = "1", b = "1";
for (int k = 3; k <= n; k++) {
string c = add(a, b);
a = b;
b = c;
}
cout << (n <= 1 ? a : b) << '\n';
return 0;
}