Cod sursa(job #2460685)

Utilizator uneven-shiverAlecu Stefan-Iulian uneven-shiver Data 24 septembrie 2019 09:42:33
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
#include <cmath>
#include <iostream>

int countFactor(int p, int n) {
  return (n < p ? 0 : (n / p + countFactor(p, n / p)));
}

int findNum(int n) {
  if (n == 0) return 1;
  if (n == 1) return 5;

  int low = 0, high = 5*n, tmp = 0;
  while (low <= high) {
    int mid = low + (high - low) / 2;
    if (countFactor(5, mid) < n) low = mid + 1;
    else {
      tmp = mid;
      high = mid - 1;
    }
  }

  return tmp;
}

int main()
{
  std::ifstream in("fact.in");
  std::ofstream out("fact.out");
  int numar;
  in >> numar;
  out << findNum(numar) << '\n';
  return 0;
}