Cod sursa(job #2741053)

Utilizator Mihai180315Mihai Smarandache Mihai180315 Data 15 aprilie 2021 13:38:31
Problema Patrate2 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.22 kb
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

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

class HugeN
{
    private:
        int x[10005];
    public:
        HugeN() {
            memset(this->x, 0, sizeof(this->x));
            this->x[0] = 1;
        }

        HugeN(int n) {
            memset(this->x, 0, sizeof(this->x));
            do
            {
                this->x[ ++this->x[0]] = n % 10;
                n = n / 10;
            }while (n);
        }

        void print() {
            for (int i = this->x[0]; i >= 1; --i) {
                fout << x[i];
            }
            fout << "\n";
        }

        HugeN operator *(int k) {
            int t = 0; HugeN c;
            c.x[0] = this->x[0];
            for (int i = 1; i <= this->x[0]; ++i)
            {
                t = this->x[i] * k + t;
                c.x[i] = t % 10;
                t /= 10;
            }
            while (t > 0)
            {
                c.x[++c.x[0]] = t % 10;
                t /= 10;
            }
            return c;
        }
        HugeN operator *(const HugeN &other) {
            int t = 0; HugeN c;
            c.x[0] = (this->x[0] + other.x[0]) - 1;
            for (int i = 1; i <= this->x[0]; ++i) {
                for (int j = 1; j <= other.x[0]; ++j) {
                    c.x[i + j - 1] += this->x[i] * other.x[j];
                }
            }
            for (int i = 1; i <= c.x[0]; ++i) {
                t = c.x[i] + t;
                c.x[i] = t % 10;
                t /= 10;
            }
            while (t > 0) {
                c.x[++c.x[0]] = t % 10;
                t /= 10;
            }
            return c;
        }
};

HugeN lgput(int e, int b)
{
    if (e == 1) {
        return HugeN (b);
    } else if (e % 2 == 1) {
        return lgput(e - 1, b) * b;
    } else {
        HugeN rez = lgput(e / 2, b);
        return rez * rez;
    }
}

int main()
{
    int n;
    fin >> n;
    HugeN aux(1);
    for (int i = 1; i <= n; ++i) {
        aux = aux * i;
    }
    HugeN a(lgput(n * n, 2));
    HugeN ans;
    ans = a * aux;
    ans.print();

    return 0;
}