Pagini recente » Cod sursa (job #2506102) | Cod sursa (job #2753093) | Cod sursa (job #2399102) | Cod sursa (job #3273236) | Cod sursa (job #30326)
Cod sursa(job #30326)
#include<stdio.h>
long nr,p;
long nz(long p)
{long nr=0;
while(p%5==0) {nr++; p=p/5;}
return nr;}
long nrzero(long n,long nri,long p)
{long nr=nri;
for(long i=p-p%5+5;i<=n;i=i+5)
nr=nr+1+nz(i/5);
return nr;}
long div(long inc,long sf,long nr)
{long m=(inc+sf)/2,nz,nrm;
nz=nrzero(m,nr,inc);
if(nz==p) return m;
if(nz<p) return div(m,sf,nz);
return div(inc,m,nr);
}
int main()
{freopen("fact.in","r",stdin);
scanf("%ld",&p);
fclose(stdin);
if(p==0) nr=1;
else nr=div(1,5*p,0);
while(nr!=1&&nr%5) nr--;
freopen("fact.out","w",stdout);
printf("%ld",nr);
fclose(stdout);
return 0;}