Cod sursa(job #1579261)
Utilizator | Data | 24 ianuarie 2016 16:13:22 | |
---|---|---|---|
Problema | Factorial | Scor | 85 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.72 kb |
#include <fstream>
using namespace std;
int main()
{
long long h,x,p;
int gr;
ifstream fin("fact.in");
ofstream fout("fact.out");
fin>>p;
x=p;
h=1;
gr=0;
if(p>=1)
{
while(h*5+1<=p)
{
h=(h*5)+1;
gr++;
}
if(((p+gr)%h)<gr)
fout<<"-1"<<"\n";
else
{
while(h!=1)
{
x-=(x/h);
h--;
h=h/5;
}
fout<<x*5;
}
}
else
if(p==0)
fout<<-1;
fout<<"\n";
fin.close();
fout.close();
return 0;
}