Cod sursa(job #3333664)
| Utilizator | Data | 14 ianuarie 2026 20:09:10 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.57 kb |
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int N;
int digits(int N) {
int ans = 0;
for (N /= 5; N; N /= 5)
ans += N;
return ans;
}
int main()
{
fin >> N;
int ans = 0;
for (int i = 29; i >= 0; --i) {
if (digits(ans + (1 << i)) < N) {
ans += (1 << i);
}
}
if (digits(ans + 1) == N) {
fout << ans + 1;
}
else {
fout << -1;
}
return 0;
}