Cod sursa(job #3341147)

Utilizator daniel_2009Stefan Daniel daniel_2009 Data 18 februarie 2026 10:53:33
Problema Patrate2 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.39 kb
#include <bits/stdc++.h>
using namespace std;

struct BigInt {
    static const int BASE = 1000000000;
    vector<int> d;

    BigInt(long long x = 0) {
        if(x == 0)
            d.push_back(0);
        else {
            while(x > 0) {
                d.push_back((int)(x % BASE));
                x /= BASE;
            }
        }
    }

    void trim() {
        while(d.size() > 1 && d.back() == 0)
            d.pop_back();
    }

    void mulSmall(long long m) {
        long long carry = 0;
        for(size_t i = 0; i < d.size(); i++) {
            long long cur = 1LL * d[i] * m + carry;
            d[i] = (int)(cur % BASE);
            carry = cur / BASE;
        }
        while(carry) {
            d.push_back((int)(carry % BASE));
            carry /= BASE;
        }
        trim();
    }

    string toString() const {
        stringstream ss;
        ss << d.back();
        for(int i = (int)d.size() - 2; i >= 0; i--) {
            ss << setw(9) << setfill('0') << d[i];
        }
        return ss.str();
    }
};

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

    int N;
    fin >> N;

    BigInt ans(1);

    int exp2 = N * N;
    for(int i = 0; i < exp2; i++)
        ans.mulSmall(2);

    for(int i = 2; i <= N; i++)
        ans.mulSmall(i);

    fout << ans.toString() << "\n";
    return 0;
}