Pagini recente » Cod sursa (job #1259727) | Cod sursa (job #1557292) | Cod sursa (job #604655) | Cod sursa (job #2795167) | Cod sursa (job #1659498)
#include <cstdio>
class hugeInt {
private:
static const int NDIG = 100;
short x[NDIG];
public:
hugeInt(int k) {
for(int i = 0; i < NDIG; i++) x[i] = 0;
do {
x[++x[0]] = k % 10;
k /= 10;
} while(k);
}
hugeInt() {
for(int i = 0; i < NDIG; i++) x[i] = 0;
x[0] = 1;
}
hugeInt operator +(const hugeInt &other) const {
hugeInt res;
int i, t;
res.x[0] = (x[0] > other.x[0] ? x[0] : other.x[0]);
for(i = 1, t = 0; i <= res.x[0]; i++) {
res.x[i] = x[i] + other.x[i] + t;
t = res.x[i] / 10;
res.x[i] %= 10;
}
if(t) {
res.x[++res.x[0]] = t;
}
return res;
}
void print() {
for(int i = x[0]; i > 0; i--) {
printf("%d", x[i]);
}
}
};
int main() {
freopen("nunta.in", "r", stdin);
freopen("nunta.out", "w", stdout);
int n, i;
scanf("%d", &n);
hugeInt f1(1), f2(2), f3(3);
for(i = 4; i <= n; i++) {
f1 = f2;
f2 = f3;
f3 = f3 + f1;
}
if(n == 1) f3 = f1;
if(n == 2) f3 = f2;
f3.print();
return 0;
}