Cod sursa(job #591221)
| Utilizator | Data | 23 mai 2011 10:46:22 | |
|---|---|---|---|
| Problema | Factorial | Scor | 25 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.55 kb |
#include<cstdio>
using namespace std;
long long unsigned int s,p,c,a,b,ok,aux;
void calcul(){
s=0;
while(c!=0){
c/=5;
s+=c;
}
}
int main(){
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%lld%",&p);
a=0;
b=100000000;
ok=0;
aux=p;
while(aux>1){
aux/=5;
}
if(aux==1)
printf("%d",-1);
else{
while(ok==0){
c=(a+b)/2;
s=0;
aux=c;
calcul();
if(s==p)
ok=1;
else{
c=aux;
if(s<p)
a=c+1;
else
b=c-1;
}
}
printf("%lld",aux-(aux-aux/5*5));
}
return 0;
}