Cod sursa(job #2333828)

Utilizator CyborgSquirrelJardan Andrei CyborgSquirrel Data 1 februarie 2019 23:28:42
Problema Patrate2 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.17 kb
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

ifstream fin("patrate2.in");
ofstream fout("patrate2.out");

struct Biggie{
	static const int LEN = 6410, BASE = 10;
	unsigned int digits[LEN];
	Biggie()
	{
		fill(digits, digits+LEN, 0);
	}
	Biggie(int num)
	{
		fill(digits, digits+LEN, 0);
		digits[0] = num;
	}
	Biggie & operator+=(const Biggie & rhs)
	{
		for(int i = 0; i < LEN-1; i++){
			digits[i] += rhs.digits[i];
			digits[i+1] += digits[i]/BASE;
			digits[i] %= BASE;
		}
		return *this;
	}
	Biggie & operator+=(const int rhs)
	{
		digits[0] += rhs;
		for(int i = 0; digits[i] < 10; i++){
			digits[i+1] += digits[i]/10;
			digits[i] %= 10;
		}
		return *this;
	}
	Biggie & operator*=(const Biggie & rhs)
	{
		int new_digits[LEN];
		fill(new_digits, new_digits+LEN, 0);
		for(int i = 0; i < LEN; i++){
			for(int j = 0; j < LEN-1-i; j++){
				int p = i+j;
				new_digits[p] += digits[j] * rhs.digits[i];
				new_digits[p+1] += new_digits[p]/BASE;
				new_digits[p] %= BASE;
			}
		}
		copy(new_digits, new_digits+LEN, digits);
		return *this;
	}
	Biggie & operator*=(const int rhs)
	{
		for(int i = LEN-2; i >= 0; i--){
			digits[i] *= rhs;
			for(int j = i; digits[j] >= 10; j++){
				digits[j+1] += digits[j]/BASE;
				digits[j] %= BASE;
			}
		}
		return *this;
	}
	Biggie & operator++()
	{
		operator+=(1);
		return *this;
	}
	Biggie operator++(int)
	{
		Biggie tmp(*this);
		operator++();
		return tmp;
	}
	void Bust()
	{
		bool write = false;
		for(int i = LEN-1; i >= 0; i--){
			if(this->digits[i] != 0){
				write = true;
			}
			if(write){
				fout << digits[i];
			}
		}
		fout << "\n";
	}
};

Biggie operator*(Biggie lhs, const Biggie & rhs)
{
	lhs *= rhs;
	return lhs;
}

Biggie Factorio(int a)
{
	Biggie b;
	b.digits[0] = 1;
	for(int i = 2; i <= a; i++){
		b *= i;
	}
	return b;
}

Biggie Kapow(int num, int exp)
{
	Biggie val(1);
	for(int i = 1; i <= exp; i++){
		val *= num;
	}
	return val;
}

Biggie a, b;
int main()
{
	int n;
	fin >> n;
	a = Factorio(n);
	//cout << "first";
	a *= Kapow(2, n*n);
	//cout << "second";
	a.Bust();
	return 0;
}