Cod sursa(job #3183984)
Utilizator | Turos Robert Daniel Spadovesky | Data | 13 decembrie 2023 20:20:41 |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.59 kb |
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
ifstream in ("fact.in");
ofstream out ("fact.out");
int check (int x) {
int a = 5, ans = 0;
while(x >= a) {
ans += x / a;
a = a * 5;
}
return ans;
}
int main() {
int n;
in >> n;
int st = 1, dr = INT_MAX - 1, ans = INT_MAX;
while(st <= dr) {
int m = (st + dr) / 2;
if(check(m) < n) st = m + 1;
else {
dr = m - 1;
ans = m;
}
}
if( check(ans) == n) out << ans;
else out << "-1";
}