Cod sursa(job #482285)
| Utilizator | Data | 2 septembrie 2010 22:57:48 | |
|---|---|---|---|
| Problema | Factorial | Scor | 5 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.51 kb |
#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;}