Pagini recente » Cod sursa (job #2154613) | Cod sursa (job #1468972) | Cod sursa (job #1629332) | Cod sursa (job #2721667) | Cod sursa (job #482285)
Cod sursa(job #482285)
#include <stdio.h>
int a[1000],p;
int nr(int k){
int temp,i=1;
temp=k/5;
while(a[i]<=k){temp+=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;
a[i]=25;
while(a[i]<=5*p){i++;a[i]=a[i-1]*5;}
printf("%d",bs(0,5*p));
return 0;}