Pagini recente » Cod sursa (job #825956) | Cod sursa (job #25200) | Cod sursa (job #224902) | Cod sursa (job #159442) | Cod sursa (job #2515231)
#include <fstream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <map>
#include <string.h>
using namespace std;
#ifdef DEBUG
string name = "data";
#else
string name = "nunta";
#endif
ifstream fin(name + ".in");
ofstream fout(name + ".out");
int n;
struct BigInt {
char digits[5005];
int size = 0;
void add(BigInt &other) {
int c = 0;
size = max(size, other.size);
for (int i = 0; i < size; ++i) {
int sum = digits[i] + other.digits[i] + c;
digits[i] = sum % 10;
c = sum / 10;
}
if (c > 0) {
digits[size] = c;
size++;
}
}
void sub(BigInt &other) {
int c = 0;
int bound = min(size, other.size);
for (int i = 0; i < bound; ++i) {
int sum = digits[i] - (other.digits[i] + c);
if (sum < 0) {
sum += 10;
c = 1;
}
else {
c = 0;
}
digits[i] = sum % 10;
}
while (c > 0) {
digits[bound]--;
if (digits[bound] < 0) {
digits[bound] = 9;
c = 1;
}
else {
c = 0;
}
bound++;
}
}
void multiply(int s) {
int c = 0;
for (int i = 0; i < size; ++i) {
int sum = digits[i] * s + c;
digits[i] = sum % 10;
c = sum / 10;
}
while (c > 0) {
digits[size] = c % 10;
c /= 10;
size++;
}
}
void multiply(BigInt& other) {
BigInt result = BigInt(0);
for (int i = 0; i < other.size; ++i) {
int ndx = i;
int c = 0;
for (int j = 0; j < size; ++j) {
int product = other.digits[i] * digits[j] + result.digits[ndx] + c;
result.digits[ndx] = product % 10;
result.size = max(result.size, ndx + 1);
c = product / 10;
ndx++;
}
if (c > 0) {
result.digits[ndx] = c;
result.size = max(result.size, ndx + 1);
}
}
size = result.size;
for (int i = 0; i < size; ++i) {
digits[i] = result.digits[i];
}
}
BigInt() {
BigInt(0);
}
BigInt(int n) {
memset(digits, 0, sizeof(digits));
while (n > 0) {
digits[size] = n % 10;
n /= 10;
size++;
}
size = max(size, 1);
}
BigInt(string s) {
size = s.size();
int j = 0;
for (int i = size - 1; i >= 0; --i) {
digits[j] = s[i] - '0';
j++;
}
}
void print() {
for (int i = size - 1; i >= 0; --i) {
fout << (int)digits[i];
}
}
};
int main() {
fin >> n;
BigInt f1 = BigInt(1);
BigInt f2 = BigInt(2);
while (n > 1) {
n--;
BigInt temp = f2;
f2.add(f1);
f1 = temp;
}
f1.print();
return 0;
}