Cod sursa(job #2463024)

Utilizator AlexNeaguAlexandru AlexNeagu Data 28 septembrie 2019 10:30:17
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int n;
int f(int x) {
  int ans = 0;
  for (int i = 5; x / i >= 1; i *= 5) {
    ans += x / i;
  }
  return ans;
}
int search_for(int cnt) {
  int l = 1, r = 2e9;
  while(l <= r) {
    int mid = (l + r) / 2;
    if (f(mid) < cnt) {
      l = mid + 1;
    }
    else {
      r = mid - 1;
    }
  }
  if (f(l) == cnt) return l;
  return -1;
}
int main() {
  in >> n;
  int ans = search_for(n);
  return out << ans, 0;
}