Cod sursa(job #1996452)
| Utilizator | Data | 1 iulie 2017 16:12:28 | |
|---|---|---|---|
| Problema | Factorial | Scor | 25 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.48 kb |
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int fact(int n)
{
int c=5*n,cnt=0;
if (n%5==0) return -1;
while (n !=cnt)
{
cnt =0;
for (int i=5; c/i>=1; i *= 5)
cnt += c/i;
if (cnt == n) return c;
if (cnt < n) c+=5;
else c-=5;
}
return c;
}
int main()
{
int n;
in >> n;
if (n==0) out << "1";
else out << fact(n);
return 0;
}
