Pagini recente » Cod sursa (job #3266059) | Borderou de evaluare (job #2372912) | Cod sursa (job #3274257) | Cod sursa (job #2346832) | Cod sursa (job #2345373)
#include <cstdio>
const int right = 100000001;
int ok(int n)
{
int count1 = 0;
for(int i=5; n/i>=1; i=i*5)
{
count1 += n/i;
}
return count1;
}
int binarySearch_Left(int st, int dr,int x)
{
int med, last =-1;
while(st<=dr)
{
med = st + (dr-st)/2;
if(ok(med) == x)
{
last = med;
dr = med -1;
}
else if(x < ok(med))
{
dr = med - 1;
} else st = med + 1;
}
return last;
}
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
int p;
scanf("%d%d",&p);
printf("%d",binarySearch_Left(1,right,p));
return 0;
}