Cod sursa(job #623964)
| Utilizator | Data | 21 octombrie 2011 10:18:42 | |
|---|---|---|---|
| Problema | Factorial | Scor | 25 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.45 kb |
using namespace std;
#include<fstream>
ifstream fin("fact.in");
ofstream fout("fact.out");
int zero (int a)
{
int s=0,p=5;
while(a>=p)
{
s=s+a/p;
p=p*5;
}
return s;
}
int main()
{
int N,p=5,a;
fin>>N;
if(N==0)
fout<<"1";
else
{
while((p-1)/4<=N)
p=p*5;
p=(p/5-1)/4;
p=p-p%5;
a=zero(p);
while(N>a)
{
p=p+5;
a=zero(p);
}
if(N<a)
fout<<"-1";
else
fout<<p;
}
return 0;
}
