Cod sursa(job #2873119)

Utilizator tedicTheodor Ciobanu tedic Data 18 martie 2022 18:02:23
Problema Factoriale Scor 40
Compilator cpp-64 Status done
Runda concursceva1 Marime 1.35 kb
#include <fstream>

using namespace std;
ifstream cin("factoriale.in");
ofstream cout("factoriale.out");
bool ciur[100005];
int ciur2[100005];
int maxx=0;



int main()
{

    ciur[0] = 1;
    ciur[1] = 1;
    for(int i = 2; i < 10000; i++)
        if(ciur[i] == 0)
            for(int j = i * i; j < 100000; j = j + i)
                ciur[j] = 1;
    int n,k,a,p=1,j;
    cin>>n>>k;
    int divizor,exp;
    for(int i=0; i<n; i++)
    {
        cin>>a;
        for(int cj=2; cj<=a; cj++)
        {
            j=cj;
            divizor = 2;
            while(divizor * divizor <= j)
            {
                exp = 0;
                while(j % divizor == 0)
                {
                    j = j / divizor;
                    exp++;
                }
                if(exp > 0)
                {
                    ciur2[divizor]+=exp;
                    maxx=max(maxx,divizor);
                }
                divizor++;
            }
            if(j > 1)
            {
                ciur2[j]++;
                maxx=max(maxx,j);
            }
        }
    }
   /// cout<<ciur2[2]<<"\n";
    for(int i=2; i<=maxx; i++)
    {
       /// cout<<i<<" "<<ciur2[i]<<'\n';
        while(ciur2[i]%k!=0)
        {
            ciur2[i]++;
            p*=i;
        }
    }
    cout<<p;
    return 0;
}