Pagini recente » Cod sursa (job #3287539) | Cod sursa (job #1818426) | Cod sursa (job #2342429) | Cod sursa (job #3281968) | Cod sursa (job #482301)
Cod sursa(job #482301)
#include <stdio.h>
int a[10000],p;
int nr(int k){
int temp,i=1;
temp=k/5;
while(a[i]<=k){temp+=k/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;}