Pagini recente » Cod sursa (job #2773301) | Cod sursa (job #577962) | Cod sursa (job #1605773) | Cod sursa (job #1889965) | Cod sursa (job #3169659)
#include <bits/stdc++.h>
#ifdef LOCAL
#define in cin
#define out cout
#endif
#define int int64_t
using namespace std;
#ifndef LOCAL
ifstream in("gfact.in");
ofstream out("gfact.out");
#endif
int countt(int maxx,int base)
{
int cnt=0;
int base1=base;
while(base1<=maxx)
{
cnt+=maxx/base1;
base1*=base;
}
return cnt;
}
signed main()
{
int p,q;in>>p>>q;
int st = 1, dr = 1e16;
while (st<dr)
{
int mid=(st+dr)/2;
//cerr<<st<<' '<<dr<<'\n';
//cerr<<mid<<' '<<p<<' '<<countt(mid,p)<<'\n';
if(countt(mid,p)>=q)
{
dr=mid;
}
else
{
st=mid+1;
}
}
out<<st;
}