Pagini recente » Cod sursa (job #1137919) | Cod sursa (job #725963) | Cod sursa (job #3003417) | Cod sursa (job #38537) | Cod sursa (job #281593)
Cod sursa(job #281593)
#include <stdio.h>
#define MAX 100000000
int n;
int bin(int p)
{
int hi,mid,lo,e,a,max;
for (lo=1, hi=MAX, max=-1; lo<=hi; )
{
mid=lo+(hi-lo)/2;
a=mid;
e=0;
while(a)
e+=(a/=5);
if (e==p)
max=mid;
if(p<=e)
hi=mid-1;
else if(p>e)
lo=mid+1;
}
if (max!=-1)
return max;
return -1;
}
int main()
{
freopen ("fact.in","r",stdin);
freopen ("fact.out","w",stdout);
scanf ("%d",&n);
if (n==0)
printf ("1");
else
printf ("%d",bin(n));
return 0;
}