Pagini recente » Cod sursa (job #3195956) | Cod sursa (job #595884) | Cod sursa (job #1781869) | Cod sursa (job #577557) | Cod sursa (job #2073657)
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
long long p;
long long fact(long long x){
long long suma=0,putere=p;
while(x/putere>0){
suma+=x/p;
putere*=p;
}
return suma;
}
int main(){
freopen("gfact.in","r",stdin);
freopen("gfact.out","w",stdout);
long long putere,s,q;
scanf("%lld%lld",&p,&q);
putere=1LL<<30;
s=0;
while(putere>0){
if(fact(s+putere)<=q-1)
s+=putere;
putere/=2;
}
printf("%lld",s+1);
return 0;
}