Cod sursa(job #3270681)

Utilizator bogdan1479Luca Bogdan Alexandru bogdan1479 Data 24 ianuarie 2025 06:41:04
Problema Patrate2 Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <fstream>
#include <iomanip>
#include <vector>

using namespace std;

const int BAZA = 1e5, MAXI = 1e5;

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

void inmultire(vector<int>&A, long long B)
{
    long long T = 0;
    for(auto &x : A)
    {
        T += x * B;
        x = T % BAZA;
        T /= BAZA;
    }
    while(T)
    {
        A.push_back(T % BAZA);
        T /= BAZA;
    }
}

void afisare(vector<int>&A)
{
    fout << A.back();
    for(int i = A.size() - 2; i >= 0; --i)
        fout << setfill('0') << setw(5) << A[i];
}

int main()
{
    ///2^(n*n) * n!
    vector<int> sol = {1};
    long long x = 1;
    int n;
    fin >> n;
    for(int i = 2; i <= n; ++i)
    {
        if(x * i < MAXI) x *= i;
        else
        {
            inmultire(sol, x);
            x = 1;
        }
    }
    if(x != 1)
    {
        inmultire(sol, x);
        x = 1;
    }
    for(int i = 1; i <= n * n; ++i)
    {
        if(x * 2 < MAXI) x *= 2;
        else
        {
            inmultire(sol, x);
            x = 1;
        }
    }
    if(x != 1) inmultire(sol, x);
    afisare(sol);
    return 0;
}