Pagini recente » Cod sursa (job #1123367) | Cod sursa (job #1483007) | Cod sursa (job #1618197) | Cod sursa (job #99945) | Cod sursa (job #147749)
Cod sursa(job #147749)
#include <stdio.h>
FILE *f=fopen("fact.in","r"), *g=fopen("fact.out","w");
long p;
long a,b;
long binar(long x)
{
long k=0,t;
t=x;
while (t)
{
k+=t/5;
t/=5;
}
if (k<p) a=x+1;
if (k>p) b=x-1;
if ((k==p)&&(x%5==0)) {
a=x;
return 0;
}
else if (k==p) b=x-1;
if ((k!=p)&&(b==x)) {
a=-1;
return 0;
}
return binar((a+b)/2);
}
int main()
{
fscanf(f,"%ld",&p);
if ((p==0) || (p==1))
{
if (p==0) fprintf(g,"1\n");
else fprintf(g,"5\n");
}
else
{
a=0;
b=1000000000;
binar((a+b)/2);
fprintf(g,"%ld\n",a);
}
fclose(g);
return 0;
}