Cod sursa(job #1711430)

Utilizator dragostanTantaru Dragos Constantin dragostan Data 31 mai 2016 10:41:17
Problema GFact Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <fstream>

using namespace std;
ifstream in("gfact.in");
ofstream out("gfact.out");
int pas=1<<30,p,q;
int nr(int);
int main()
{
    int a,i=0;
    in >> p >> q;
    while(pas)
    {
        if(nr(i+pas)<=q)
            i+=pas;
        pas/=2;
    }
    while(nr(i)==q)
        i--;
    out << i+1;
    return 0;
}
int nr(int n)
{
    int div=0;
    while(n>=p)
    {
        div+=n/p;
        n/=p;
    }
    return div;
}