Cod sursa(job #148648)
| Utilizator | Data | 4 martie 2008 17:31:42 | |
|---|---|---|---|
| Problema | Factorial | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.63 kb |
#include<fstream.h>
long long n,p,aux,x=0,i=0,y;
int main ()
{
ifstream f("fact.in");
ofstream g("fact.out");
f>>p;
if (p==0) g<<1;
else {
while (x<p)
{
aux=i;y=x;
i+=25;x+=5;
if (x>p)
{
i=aux;x=y;
while (x<p)
{i+=5;x++;}
break;}
}
if (i>=390625) i-=28*5;
else if (i>=78125) i-=21*5;
else if (i>=15625) i-=15*5;
else if (i>=3125) i-=10*5;
else if (i>=625) i-=6*5;
else if (i>=125) i-=3*5;
else if (i>=25) i-=1*5;
if (x==p) g<<i;
else g<<-1;
}
f.close();
g.close();
return 0;
}
