Pagini recente » Cod sursa (job #165306) | Rating Vlad Andrei Raducan (andreivlad) | Cod sursa (job #2282736) | Cod sursa (job #2504758) | Cod sursa (job #1659482)
#include <fstream>
using namespace std;
ifstream in("nunta.in");
ofstream out("nunta.out");
class hugeInt {
private:
static const int NDIG = 1005;
int x[NDIG];
public:
hugeInt(int k) {
fill(x, x+NDIG, 0);
do {
x[++x[0]] = k % 10;
k /= 10;
} while(k);
}
hugeInt() {
fill(x, x+NDIG, 0);
x[0] = 1;
}
hugeInt operator +(const hugeInt &other) const {
hugeInt res;
int i, t;
res.x[0] = max(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--) {
out << x[i];
}
}
};
int main() {
int n, i;
in >> 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;
}