Pagini recente » Cod sursa (job #558280) | Cod sursa (job #1583773) | Cod sursa (job #1509623) | Cod sursa (job #923668) | Cod sursa (job #535821)
Cod sursa(job #535821)
#include<stdio.h>
#include<math.h>
long int p;
long int cauta(long int a,long int b)
{
long int c=(a+b)/2,s=0;
int y=5;
while(y<=c)
{
s+=c/y;
y*=5;
}
if(s==p) {if(c%5) return c-c%5; else return c;}
else {if(a==b) return -1;
if(s<p) return cauta(c+1,b);
if(s>p) return cauta(a,c-1);
}
}
int main()
{
long int x;
FILE *f=fopen("fact.in","rt");
fscanf(f,"%ld",&p);
FILE *h=fopen("fact.out","wt");
if(p==0) fprintf(h,"1");
else if(p==1) fprintf(h,"5");
else {x=cauta(4*p,5*p); fprintf(h,"%ld",x);}
return 0;
}