Mai intai trebuie sa te autentifici.
Cod sursa(job #252413)
| Utilizator | Data | 4 februarie 2009 13:39:19 | |
|---|---|---|---|
| Problema | Factorial | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.7 kb |
# include <fstream>
using namespace std;
int main ()
{
long long int p, i, nrz=0, c, n, x[100], y[100], s;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
x[1]=1, y[1]=5;
for (i=2;i<=14;i++)
x[i]=x[i-1]*5+1, y[i]=y[i-1]*5;
fin>>p;
if (p==0)
fout<<"1";
else
{
for (i=1;i<12 && nrz==0;i++)
if (p>x[i] && p<x[i+1])
s=y[i], nrz=x[i];
for (i=s+5;nrz<p;i+=5)
{
c=i, n=i;
while (c%5==0)
{
nrz++;
c/=5;
}
}
if (nrz==p)
fout<<n;
else
fout<<"-1";
}
return 0;
}
