Cod sursa(job #326979)
| Utilizator | Data | 26 iunie 2009 19:11:18 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.47 kb |
#include<cstdio>
int p;
int zero(int n)
{
int rez=0;
while(n)
{
n/=5;
rez+=n;
}
return rez;
}
int calcul()
{
if(p==0)
return 1;
int z,st=5,dr=1<<30,m;
while(st!=dr)
{
m=(st+dr)>>1;
z=zero(m);
if(p<=z)
dr=m;
else
st=m+1;
}
z=zero(st);
if(z==p)
return st;
return -1;
}
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
printf("%d\n",calcul());
return 0;
}
