Cod sursa(job #3328117)
| Utilizator | Data | 6 decembrie 2025 11:33:38 | |
|---|---|---|---|
| Problema | Factorial | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.54 kb |
#include <bits/stdc++.h>
using namespace std;
int main()
{
ifstream cin("fact.in");
ofstream cout("fact.out");
int p; cin >> p;
int l = 0, r = 50;
if (p == 0)
{
cout << 1;
return 0;
}
for (int i = 2; i <= 60; i ++)
{
if (p == pow(5, i))
{
cout << -1;
return 0;
}
}
while (r - l > 1)
{
int mid = (l + r) / 2;
if (pow(5, mid) <= 5 * p)
l = mid;
else
r = mid;
}
cout << 5 * (p - l + 1);
}
