Cod sursa(job #2131204)
Utilizator | Data | 14 februarie 2018 15:20:57 | |
---|---|---|---|
Problema | Factorial | Scor | 85 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.61 kb |
#include <fstream>
#define ll long long
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int nz(int x)
{
ll s=0;
while(x>4)
{
x/=5;
s+=x;
}
return s;
}
int main()
{
ll p;
int k;
fin>>p;
if(p==0)
fout<<"1";
else
{
k=p*5;
bool ok=0;
ll z=nz(k);
while(z!=p)
{
k=k-5*(z-p);
z=nz(k);
if(z==p)
ok=1;
}
if(ok==0)
fout<<"-1";
else
fout<<k;
}
return 0;
}