Cod sursa(job #1714048)

Utilizator lucametehauDart Monkey lucametehau Data 7 iunie 2016 11:22:19
Problema GFact Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include <fstream>

using namespace std;
ifstream cin("gfact.in");
ofstream cout("gfact.out");
int legendre(int f,int n)
{
    int c,p=0;
    c=f;
    while(c<=n)
    {
        p+=n/c;
        c*=f;
    }
    return p;
}
int main()
{
    int p,q,st,dr,m;
    cin>>p>>q;
    st=1;
    dr=2000000000;
    while(st<dr)
    {
        m=(st+dr)/2;
        if(legendre(p,m)>=q)
            dr=m-1;
        else
            st=m+1;
    }
    cout<<st;
    return 0;
}