Cod sursa(job #1728183)

Utilizator ade_tomiEnache Adelina ade_tomi Data 12 iulie 2016 13:38:51
Problema GFact Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include<iostream>
#include<fstream>
#include<climits>

using namespace std ;
typedef unsigned long long ull;
ull desc(ull k,ull b)
{

    ull sol=0,nr=k;
    while(nr<=b)
    {
        sol+=b/nr;
        nr*=k;
    }
    return sol;
}
ull fact[505],put[505];
int main()
{

    ull p,q,l1,l2,mid,m=0,i,ok,rad,sol=0;

    ifstream cin("gfact.in");
    ofstream cout("gfact.out");
    cin>>p>>q;
    l1=1;
    l2=ULLONG_MAX-1;
   // rad=sqrt(p);
    for(i=2;i<=p;i++)
    {

        if(p%i==0)
        {

            m++;
            fact[m]=i;
            while(p%i==0)
            {

                p/=i;
                put[m]++;
            }
        }
    }
    while(l1<=l2)
    {

        mid=(l1+l2)/2;
        ok=0;
        for(i=1;i<=m;i++)
        {
            if(desc(fact[i],mid)<q*put[i])
                ok=1;
        }

        if(ok==0)
        {

            sol=mid;
            l2=mid-1;
        }
        else
            l1=mid+1;
    }
    cout<<sol;
    return 0;


}