Pagini recente » Cod sursa (job #76245) | Cod sursa (job #3274597) | Cod sursa (job #2806100) | Cod sursa (job #514307) | Cod sursa (job #73317)
Cod sursa(job #73317)
#include <stdio.h>
FILE *f1,*f2;
long x,m,p,c,s,ok1,ok2;
void putere(long x)
{
p=1;
s=0;
while (p*5<=x)
{
p=p*5;
s=s+x/p;
}
}
void search(long li,long ls)
{
m=(li+ls)/2;
putere(m);
ok1=s;
putere(m-1);
ok2=s;
if (ok1==x && ok2<x) c=m;
else if (li<ls)
if (ok2>=x) search(li,m-1);
else search(m+1,ls);
}
int main()
{
f1=fopen("fact.in","r");
f2=fopen("fact.out","w");
fscanf(f1,"%ld",&x);
search(1,1000000000);
if (c==0) c--;
if (x==0) c=1;
fprintf(f2,"%ld",c);
fclose(f1);
fclose(f2);
return(0);
}