Cod sursa(job #3141915)
Utilizator | C. Eric-Dimitrie EricDimi | Data | 17 iulie 2023 17:24:03 |
---|---|---|---|
Problema | Factorial | Scor | 35 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
string nume = "fact";
ifstream f(nume + ".in");
ofstream g(nume + ".out");
long long n, p = 0, cnt, x;
int main()
{
f >> n;
if (n == 0)
p = 1;
else
{
cnt = n;
x = 5 * n;
while (cnt >= n)
{
cnt = 0;
p = 5;
while (p <= x)
cnt += (x / p), p *= 5;
if (cnt == n)
{
g << x;
return 0;
}
x -= 5;
}
g << -1;
}
return 0;
}