Pagini recente » Cod sursa (job #292408) | Cod sursa (job #487723) | Cod sursa (job #939999) | Cod sursa (job #3204510) | Cod sursa (job #480776)
Cod sursa(job #480776)
#include <stdio.h>
long n,max;
void caut(long i, long j)
{
if (i<=j) {
long p,x=0,m=(i+j)/2;
int q=1;
p=5;
while (q<12 && p<=m) {x+=m/p; p*=5;}
if (x==n && (m<max || max==-1)) {max=m; caut(i,m-1);}
else if (x>n) caut(i,m-1);
else caut(m+1,j);
}
}
int main() {
FILE *f,*g;
f=fopen("fact.in","r");
g=fopen("fact.out","w");
fscanf(f,"%ld",&n);
max=-1;
if (n==0) fprintf(g,"0");
else {
caut (1,n*5);
fprintf(g,"%ld",max);
}
fclose(g);
return 0;
}