Pagini recente » Cod sursa (job #488270) | Cod sursa (job #324110) | Cod sursa (job #834542) | Cod sursa (job #2229441) | Cod sursa (job #3310348)
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
ifstream fin("nunta.in");
ofstream fout("nunta.out");
const int MAX_L = 200;
const int B = 100000;
struct BigInt {
int c[MAX_L + 1];
int lg;
BigInt(): lg(0) {};
BigInt(int n) {
lg = 0;
while (n > 0) {
c[lg++] = n % B;
n /= B;
}
}
BigInt& operator = (const BigInt &x) {
lg = x.lg;
for (int i = 0; i < lg; i++)
c[i] = x.c[i];
return *this;
}
friend BigInt operator + (const BigInt &x, const BigInt &y) {
BigInt z;
z.lg = (x.lg > y.lg ? x.lg : y.lg);
int t = 0;
for (int i = 0; i < z.lg; i++) {
t += x.c[i] + y.c[i];
z.c[i] = t % B;
t /= B;
}
while (t > 0) {
z.c[z.lg++] = t % B;
t /= B;
}
return z;
}
friend ostream& operator << (ostream &out, const BigInt &x) {
out << x.c[x.lg - 1];
for (int i = x.lg - 2; i >= 0; i--)
out << setw(6) << setfill('0') << x.c[i];
return out;
}
};
BigInt a(1), b(2), c;
int N;
int main() {
fin >> N;
if (N <= 2) {
if (N == 1)
fout << a << '\n';
else
fout << b << '\n';
fin.close();
fout.close();
return 0;
}
for (int i = 3; i <= N; i++) {
c = a + b;
a = b;
b = c;
}
fout << c << '\n';
fin.close();
fout.close();
return 0;
}