Mai intai trebuie sa te autentifici.
Cod sursa(job #1700201)
Utilizator | Data | 9 mai 2016 19:59:12 | |
---|---|---|---|
Problema | GFact | Scor | 15 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("gfact.in");
ofstream out("gfact.out");
long long p;
int q;
long long nr( long long x )
{
long long s = 0;
while( x >= p )
{
s+=x/p;
x/=p;
}
return s;
}
long long cautare()
{
long long pas = 1LL << 40, i = 0, x;
while( pas != 0 )
{
x = nr(i+pas);
if ( x < q )
{
i+=pas;
}
pas/=2;
}
return i;
}
int main()
{
in >> p >> q;
out << cautare()+1;
return 0;
}