Cod sursa(job #367574)
Utilizator | Data | 22 noiembrie 2009 18:43:08 | |
---|---|---|---|
Problema | Factorial | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.38 kb |
#include<fstream.h>
int cinci(int x)
{
long p=0;
while(x>=5)
p+=x/5,x/=5;
return p;
}
int main()
{
long p,x,ante;
ifstream in("fact.in");
ofstream out("fact.out");
in>>p;
long z=p;
x=p;
while(z)
x-=z/5,z/=5;
z=p/5;
while(z>=5)
x+=(z/5),z/=5;
x*=5;
if(x==0) x=1;
if(p==cinci(x)) out<<x;
else out<<-1;
return 0;
}