Pagini recente » Cod sursa (job #2562697) | Cod sursa (job #2762025) | Cod sursa (job #1053616) | Cod sursa (job #366565) | Cod sursa (job #29455)
Cod sursa(job #29455)
#include<stdio.h>
long p,found;
int check(long m){
long i;
long aux;
for(i=0;m>0;i++){
for(aux=m;aux%5==0;aux/=5)
i++;
m--;
}
if(i<p)
return 1;
else
if(i==p)
return 0;
else
return -1;
}
void binsrc(long ld,long ls){
long m=(ld+ls)/2;
if(ld>ls){
found=-1;
return;
}
int i=check(m);
if(i==-1)
binsrc(ld,m-1);
else
if(i==0){
found=m*5;
return;
}
else
binsrc(m+1,ls);
}
int main(){
freopen("fact.in","rt",stdin);
freopen("fact.out","w+",stdout);
scanf("%ld",&p);
if(p==0){
printf("1");
return 0;
}
if(p==1){
printf("5");
return 0;
}
binsrc(0,200000);
printf("%ld",found);
}