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