Cod sursa(job #137134)
| Utilizator | Data | 16 februarie 2008 23:04:07 | |
|---|---|---|---|
| Problema | Factorial | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.66 kb |
#include <stdio.h>
int st,dr,c;
int n,p;
int main ()
{
freopen ("fact.in","r",stdin);
freopen ("fact.out","w",stdout);
int i,aux;
scanf ("%d",&p);
if (p==0)
{
printf ("1");return 0;
}
st=4*p-1;
dr=5*p+1;
while (st<dr)
{
i=0;
c=(st+dr)/2;
aux=c;
while (aux)
{
i+=aux/5;
aux/=5;
}
if (i==p)
{
c/=5;
c*=5;
printf ("%d",c);return 0;
}
if (i>p)
dr=c;
else if (i<p)
st=c;
}
if (i==p)
{
c/=5;
c*=5;
printf ("%d",c);
}
else
printf ("-1");
return 0;
}
