Cod sursa(job #2764939)

Utilizator DragosC1Ciobanu Dragos DragosC1 Data 23 iulie 2021 18:39:14
Problema Patrate2 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 kb
// formulat 2^(n * n) * n!
#include <fstream>
using namespace std;

int n;
int baza = 1000;

typedef int bigNr[10001];

bigNr rez;

void read() {
    ifstream f("patrate2.in");
    f >> n;
    f.close();
}

void solve() {
    int i, t, j;
    rez[0] = rez[1] = 1;
    for (i = 1; i <= n; i++) {
        t = 0;
        for (j = 1; j <= rez[0]; j++) {
            t = t + rez[j] * i;
            rez[j] = t % baza;
            t /= baza;
        }
        while (t) {
            rez[++rez[0]] = t % baza;
            t /= baza;
        }
    }
    for (i = 1; i <= n * n; i++) {
        t = 0;
        for (j = 1; j <= rez[0]; j++) {
            t = t + rez[j] * 2;
            rez[j] = t % baza;
            t /= baza;
        }
        while (t) {
            rez[++rez[0]] = t % baza;
            t /= baza;
        }
    }
}

void output() {
    int i, x;
    ofstream g("patrate2.out");
    g << rez[rez[0]];
    for (i = rez[0] - 1; i >= 1; i--) {
        x = rez[i];
        if (x < 10)
            g << "00";
        else if (x < 100)
            g << "0";
        g << x;
    }
    g.close();
}

int main() {
    read();
    solve();
    output();
    return 0;
}