Cod sursa(job #935976)
Utilizator | Data | 5 aprilie 2013 12:12:34 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.47 kb |
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
long long p,s,i,j,r,k;
int main()
{
fin>>p;
j=p-p/5-1;
s=0;
k=0;
while (s!=p&&j<p&&k<100000)
{
k++;
j++;
s=0;
i=j;
while (i>0)
{
s+=i;
i/=5;
}
}
if (p==0)
fout<<1;
else
if (s==p)
fout<<j*5;
else
fout<<-1;
return 0;
}