Cod sursa(job #585225)

Utilizator darrenRares Buhai darren Data 28 aprilie 2011 16:59:42
Problema Factoriale Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream>

using namespace std;

bool prim(int x)
{
    if (x == 2) return true;
    if (x % 2 == 0) return false;
    for (int i = 3; i * i <= x; i += 2)
        if (x % i == 0) return false;
    return true;
}

int N, K;
int X[102];
long long result = 1;

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

    fin >> N >> K;
    for (int i = 1; i <= N; ++i)
        fin >> X[i];

    for (int i = 2; i < 100; ++i)
        if (prim(i))
        {
            int times = 0;
            for (int j = 1; j <= N; ++j)
            {
                int aux = i;
                while (aux <= X[j])
                    times += X[j] / aux,
                    aux *= i;
            }

            times = (times % K == 0 ? 0 : K - times % K);
            while (times--) result *= i;
        }

    fout << result;

    fin.close();
    fout.close();
}