Cod sursa(job #2074302)

Utilizator verde.cristian2005Verde Flaviu-Cristian verde.cristian2005 Data 24 noiembrie 2017 13:53:06
Problema GFact Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <fstream>
using namespace std;
ifstream in("gfact.in");
ofstream out("gfact.out");
unsigned long long div[11],p,q,j,exp[11];
bool verif(unsigned long long n)
{
    unsigned long long cnt=0,cat=0,i;
    for(i=1; i<=j; i++)
    {
        cnt=0;
        cat=n/div[i];
        while(cat)
        {
            cnt+=cat;
            cat/=div[i];
        }
        if(cnt<exp[i])
            return 0;
    }
    return 1;
}
void cautbin()
{
    unsigned long long r=0,pas=1LL<<63;
    while(pas)
    {
        if(verif(r+pas)==0)
            r+=pas;
        pas/=2;
    }
    out<<r+1;
}
void desc()
{
    unsigned long long d=2,cnt=0;
    while(d*d<=p)
    {
        cnt=0;
        while(p%d==0)
        {
            p/=d;
            cnt++;
        }
        if(cnt!=0)
        {
            div[++j]=d;
            exp[j]=cnt*q;
        }
        d++;
    }
    if(p!=1)
    {
        div[++j]=p;
        exp[j]=q;
    }
}
int main()
{
    in>>p>>q;
    desc();
    cautbin();
    return 0;
}