Pagini recente » Cod sursa (job #1975573) | Cod sursa (job #2609306) | Cod sursa (job #2464194) | Cod sursa (job #2605927) | Cod sursa (job #480777)
Cod sursa(job #480777)
#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,"1");
else {
caut (1,n*5);
fprintf(g,"%ld",max);
}
fclose(g);
return 0;
}