Cod sursa(job #2356366)
Utilizator | Data | 26 februarie 2019 17:16:56 | |
---|---|---|---|
Problema | GFact | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.52 kb |
#include <bits/stdc++.h>
using namespace std;
int main()
{
freopen("gfact.in","r",stdin);
freopen("gfact.out","w",stdout);
int st=1,dr=15,p,q;
scanf("%d%d",&p,&q);
while(st<=dr)
{
int med=(st+dr)/2;
int x=0,p1=1,pl=med;
while(pl)
{
x+=pl/p;
pl/=p;
}
if(x>q)dr=med-1;
if(x==q)
{
printf("%d\n",med/p*p);
return 0;
}
if(x<q)st=med+1;
}
return 0;
}