Cod sursa(job #2414076)

Utilizator circeanubogdanCirceanu Bogdan circeanubogdan Data 24 aprilie 2019 04:10:43
Problema Factoriale Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.56 kb
#include <fstream>
#define DIM 102

using namespace std;

ifstream in ("factoriale.in");
ofstream out("factoriale.out");

int n, k, x;
int v[DIM], divCrt[DIM];
int divPrim[DIM][DIM];

void mul(int a[], int b[], int x){
    int t = 0;
    for(int i = 1; i <= b[0]; ++ i){
        a[i] = (t + b[i] * x);
        t = a[i] / 10;
        a[i] = a[i] % 10;
    }
    
    a[0] = b[0];
    while(t != 0){
        a[++a[0]] = t % 10;
        t = t / 10;
    }
    for(int i = 1; i <= a[0]; ++ i)
        b[i] = a[i];
    b[0] = a[0];
}

int main(int argc, const char * argv[]) {
    
    in>>n>>k;
    divPrim[0][1] = divPrim[0][1] = 1;
    for(int i = 0; i <= 100; ++ i){
        int x = i;
        for(int d = 2; d * d <= x; ++ d){
            while(x % d == 0){
                x /= d;
                divPrim[i][d] ++;
            }
        }
        if(x != 1){
            divPrim[i][x] ++;
        }
        for(int j = 1; j <= 100; ++ j){
            divPrim[i][j] += divPrim[i - 1][j];
        }
    }
    
    for(int i = 1; i <= n; ++ i){
        in>>x;
        for(int j = 1; j <= 100; ++ j){
            divCrt[j] += divPrim[x][j];
        }
    }
    
    int res[10000] = {0}, aux[10000] = {0};
    
    res[0] = res[1] = 1;
    
    long long Res = 1;
    
    for(int i = 1; i <= 100; ++ i){
        int mod = (k - divCrt[i] % k);
        if(mod == k)
            mod = 0;
        for(int j = 1; j <= mod; ++ j){
            mul(aux, res, i);
//            Res *= i;
        }
    }
//    out<<Res;
    for(int i = res[0]; i >= 1; -- i)
        out<<res[i];
    
    
    return 0;
}