Cod sursa(job #1742774)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 17 august 2016 00:26:43
Problema Sarpe Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.97 kb
#include <fstream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

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

#define A (*this)
class Huge : protected vector < int > {

protected:

	static const int base = 1000000000, nBase = 9;

public:

	Huge() {
		this->resize(4000);
	}

	Huge(int x) {
		this->resize(4000);
		A = x;
	}

	Huge(char* s) {
		this->resize(4000);
		A = s;
	}

	void operator = (int x) {
		for (A[0] = 0; x; x /= base)
			A[++A[0]] = x % base;
	}

	void operator = (char *s) {
		A[0] = 0;
		for (int i = strlen(s); i > 0; i -= nBase) {
			++A[0];
			for (int j = max(0, i - nBase); j < i; ++j)
				A[A[0]] = A[A[0]] * 10 + s[j] - '0';
		}
	}

	void print(void) {
		if (A[0] == 0) {
			fout << 0;
			return;
		}
		fout << A[A[0]];
		for (int i = A[0] - 1; i > 0; --i) {
			int p = base / 10;
			while (p > A[i] && p > 1) {
				fout << 0;
				p /= 10;
			}
			fout << A[i];
		}
	}

	bool operator < (const Huge &B) {
		if (A[0] != B[0])
			return A[0] < B[0];
		for (int i = A[0]; i; --i) {
			if (A[i] < B[i]) return true;
			if (B[i] < A[i]) return false;
		}
		return true;
	}

	Huge operator + (const Huge &B) {
		int i, t = 0;
		Huge C;
		for (i = 1; i <= A[0] || i <= B[0] || t; ++i, t /= base) {
			t += (i <= A[0] ? A[i] : 0);
			t += (i <= B[0] ? B[i] : 0);
			C[i] = t % base;
		}
		C[0] = i - 1;
		return C;
	}

	Huge operator - (const Huge &B) {
		Huge C = A;
		int i, t = 0;
		for (i = 1; i <= A[0]; ++i) {
			C[i] -= (i <= B[0] ? B[i] : 0) + t;
			t = 0;
			if (C[i] < 0) C[i] += base, t = 1;
		}
		while (C[0] > 1 && C[C[0]] == 0)
			--C[0];
		return C;
	}

	Huge operator * (int x) {
		Huge C = A;
		long long t = 0;
		for (int i = 1; i <= C[0]; ++i) {
			t = 1LL * C[i] * x + t;
			C[i] = t % base;
			t /= base;
		}
		while (t) {
			C[++C[0]] = t % base;
			t /= base;
		}
		return C;
	}

	Huge operator * (const Huge &B) {
		Huge C;
		for (int i = 1; i <= A[0]; ++i) {
			long long t = 0; int j;
			for (j = 1; j <= B[0] || t; ++j, t /= base) {
				t += C[i + j - 1] + (j <= B[0] ? 1LL * A[i] * B[j] : 0);
				C[i + j - 1] = t % base;
			}
			if (i + j - 2 > C[0])
				C[0] = i + j - 2;
		}
		return C;
	}

	Huge operator / (int x) {
		Huge C;
		C = A;
		long long R = 0;
		for (int i = A[0]; i; --i) {
			R = R * base + A[i];
			C[i] = int(R / x);
			R %= x;
		}
		while (C[0] > 1 && C[C[0]] == 0)
			--C[0];
		return C;
	}

	int operator % (int x) {
		long long R = 0;
		for (int i = A[0]; i; --i) {
			R = R * base + A[i];
			R %= x;
		}
		return (int)R;
	}

	bool operator == (const Huge& B) const{

		return A.data() == B.data();

	}

};
#undef A

int main() {

	char num[1005];
	fin >> num;

	Huge n(num);

	//SOL = 4N + 2(N-1)(N-2)
	if (n == 1) {
		fout << "2\n";
	}
	else {
		Huge sol = n * 4 + (n - 1)*(n - 2) * 2;
		sol.print();
	}

	return 0;

}

//Trust me, I'm the Doctor!