Pagini recente » Cod sursa (job #1996664) | Cod sursa (job #169756) | Cod sursa (job #1275308) | Cod sursa (job #64744) | Cod sursa (job #482303)
Cod sursa(job #482303)
#include <stdio.h>
int a[1000],p;
int nr(int k){
int temp,i=1;
temp=k/5;
while(a[i]<=k){temp+=k/a[i];i++;}
return temp;
}
int bs(int lo,int hi){
int mid;
while(lo<hi){
mid=lo+(hi-lo)/2;
if(nr(mid)>=p){hi=mid;}else{lo=mid+1;}
}
if(nr(lo)==p){return lo;}else{return -1;}
}
int main(){
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
int i=1;
if(p==0){printf("1");}else{
a[i]=25;
while(a[i]<=5*p){i++;a[i]=a[i-1]*5;}
printf("%d",bs(0,5*p));
}
return 0;}