Cod sursa(job #2099681)

Utilizator AlexandruabcdeDobleaga Alexandru Alexandruabcde Data 4 ianuarie 2018 16:44:19
Problema GFact Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <fstream>

using namespace std;
ifstream f ("gfact.in");
ofstream g ("gfact.out");
int p,q,exp,d;
long long i,step,Max;
int verif (int n, int x)
{
    int nr=0;
    while (n>=x)
    {
        nr+=n/x;
        n=n/x;
    }
    return nr;
}
int main()
{
    f>>p>>q;
    d=2;
    while (p!=1 && d*d<=p)
    {
        exp=0;
        while (p%d==0)
        {
            exp++;
            p=p/d;
        }
        if (exp!=0)
        {
            step=1<<31;
            for (i=0; step; step>>=1)
            {
                if (verif(i+step,d)<q*exp)
                {
                    i+=step;
                }
            }
            if (i>Max) Max=i;
        }
        d++;
    }
    if (p!=1)
    {
        step=1<<31;
        for (i=0; step; step>>=1)
        {
            if (verif(i+step,p)<q)
            {
                i+=step;
            }
        }
        if (i>Max) Max=i;
    }
    g<<i+1<<'\n';
    return 0;
}