Cod sursa(job #605861)
| Utilizator | Data | 2 august 2011 14:53:57 | |
|---|---|---|---|
| Problema | Factorial | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.43 kb |
#include <fstream.h>
fstream f("fact.in");
ofstream g("fact.out");
int fact(int p);
int main()
{
int p;
f>>p;
g<<fact(p);
f.close();
g.close();
return 0;
}
int fact(int p)
{
if(p==0)
return 1;
int i=0,n=4*p,x=n;
while((n++)%5!=0);
n--;
while(i<p)
{
i=0;
x=n;
while(x>0)
{
x=x/5;
i+=x;
}
n+=5;
}
if(i==p)
return (n-5);
else
return -1;
}