Cod sursa(job #2234823)

Utilizator TeodorLuchianovTeo Luchianov TeodorLuchianov Data 26 august 2018 10:43:29
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream in("fact.in");
ofstream out("fact.out");

int n0fact(int n, int p, int ans) {
  if(n == 0){
    return ans;
  }else{
     return n0fact(n / 5, p, ans + n / 5);
  }
  return ans;
}

int cautbin5(int from, int to, int p) {
  if(from == to) {
    return from;
  } else {
    int mid = (from + to) / 2;//[]
    if(n0fact(mid, p, 0) >= p) {
      return cautbin5(from, mid, p);
    } else {
      return cautbin5(mid + 1, to, p);
    }
  }
}

int main() {//cautbin5
  int p;
  in >> p;
  int n = cautbin5(1, p * 5 + 1, p);
  if(n0fact(n, p, 0) == p){
    out << n;
  }else{
     out << -1;
  }
  return 0;
}