Cod sursa(job #1570084)
| Utilizator | Data | 16 ianuarie 2016 10:47:45 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.46 kb |
#include <cstdio>
#define NMax 500000001
int zero(int x)
{ int i=5,s=0;
while(x/i)
{ s+=x/i; i*=5; }
return s;
}
int main(){
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
int n,ok,mid,st,dr,i,p;
scanf("%d",&p);
for(st=1,dr=NMax,ok=0;st<=dr;)
{ mid=(st+dr)/2;
if(zero(mid)>p) dr=mid-1;
else if(zero(mid)<p) st=mid+1;
else { ok=1; n=mid; dr=mid-1; }
}
if(!ok) printf("-1");
else printf("%d",n);
return 0;
}
