Cod sursa(job #137135)
| Utilizator | Data | 16 februarie 2008 23:06:58 | |
|---|---|---|---|
| Problema | Factorial | Scor | 95 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.69 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;
if (dr-st==2)
break;
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;
}
