Cod sursa(job #2285869)
| Utilizator | Data | 19 noiembrie 2018 14:03:33 | |
|---|---|---|---|
| Problema | Factorial | Scor | 5 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.7 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long p,n,m5,k,cont,cn;
int main()
{
f>>p;
if(p==0)
g<<"1";
else
{
n=p*5;
cn=n;
while(cn%10==0||cn%10==5)
cn=cn/5;
if(cn==1)
g<<"-1";
else
{
m5=25;
k=1;
cont=2;
while(m5<n)
{
while(m5*k<n)
{
n=n-5*(cont-1);
k++;
}
m5=m5*5;
cont++;
}
g<<n;
}
}
return 0;
}
