Cod sursa(job #3310347)

Utilizator EricDimiCismaru Eric-Dimitrie EricDimi Data 13 septembrie 2025 09:06:39
Problema Nunta Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.3 kb
#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];
	}
	
	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;
}