Pagini recente » Cod sursa (job #2794091) | Cod sursa (job #100143) | Cod sursa (job #784148) | Cod sursa (job #1436895) | Cod sursa (job #12955)
Cod sursa(job #12955)
#include<stdio.h>
#include<math.h>
long int n,c,b,a,k,p;
long int h(long int x)
{
long int y=0;
while(x)
{
y=y+x/5;
x=x/5;
}
return y;
}
long int divide(long int a,long int b)
{
long int putere;
//putere = h(c);
while(a<b)
{
c=(a+b)/2;
putere=h(c);
if(putere<p) a=c;
else if(putere>p) b=c;
else return c;
}
}
int main()
{
FILE *in=fopen("fact.in","rt");
fscanf(in,"%ld",&p);
fclose(in);
FILE *out=fopen("fact.out","wt");
if(p==0) {
fprintf(out,"1");
return 0;
}
a=0;b=5000000000;
k=divide(a,b);
while(k%5) --k;
if(h(k)==p) fprintf(out,"%ld",k);
else fprintf(out,"-1");
fclose(out);
return 0;
}