Cod sursa(job #6218)
Utilizator | Data | 18 ianuarie 2007 15:13:58 | |
---|---|---|---|
Problema | Factorial | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.45 kb |
#include<fstream.h>
#define input "fact.in"
#define output "fact.out"
int main()
{
long long h,x,p;
int gr;
ifstream fin(input);
ofstream fout(output);
fin>>p;
x=p;
h=1;
gr=0;
if(p==0)
fout<<"0\n";
else
while(h*5+1<=p)
{
h=(h*5)+1;
gr++;
}
if(p+gr>=(h*5)+1)
fout<<"-1"<<"\n";
else
{
while(h!=1)
{
x-=(x/h);
h--;
h=h/5;
}
fout<<x*5<<"\n";
}
return 0;
}