Cod sursa(job #1247149)
| Utilizator | Data | 22 octombrie 2014 10:28:06 | |
|---|---|---|---|
| Problema | Factorial | Scor | 35 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.54 kb |
#include<stdio.h>
int p;
int zero ( int n){
int rez=0;
while(n>=5){
rez+=n/5;
n/=5;
}
return rez;
}
int caut ( int numar){
int i=1, pas=1<<23;
while(pas!=0){
if(zero(i+pas)<p)
i+=pas;
pas>>=1;
}
if(zero(i+1+pas)==p)
return i+1;
return -1;
}
int main(){
int x;
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
if(p==0)
printf("1\n");
else{
x=caut(p);
printf("%d\n",x);
}
return 0;
}
