Cod sursa(job #2187149)

Utilizator VladAfrasineiAfrasinei VladAfrasinei Data 26 martie 2018 11:42:19
Problema GFact Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("gfact.in");
ofstream fout("gfact.out");
int q,p;
int maxd,put;
unsigned long long s;
int main()
{
    int i,d,nr,j;
    unsigned long long n,dr,mij,st,t,c,z,maxi=0;
fin>>p>>q;
d=2;
c=p;
while(c!=1)
{
    t=0;
    while(c%d==0)
    {
        t++;
        c=c/d;
    }
    if(t>0)
    {   z=1;
        for(j=1;j<=t;j++)
            z=z*d;
        if(z>maxi)
        {maxd=d;
        put=t;
        maxi=z;
        }
    }
    if(d*d<c)
        d++;
    else
        d=c;
}
n=1;
put=put*q;
for(i=1;i<=put;i++)
    n=n*maxd;
st=1;
dr=n;
s=n;
while(st<=dr)
{
    mij=(st+dr)/2;
    nr=0;
    t=1;
    for(i=1;i<=put;i++)
    {
     t=t*maxd;
     nr+=mij/t;
    }
    if(nr<put)
        st=mij+1;
    else
    {
        if(mij<s)
            s=mij;
        dr=mij-1;
    }
}
fout<<s;
    return 0;
}