Cod sursa(job #2234082)

Utilizator TeodorLuchianovTeo Luchianov TeodorLuchianov Data 25 august 2018 11:57:18
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n0fact(int n) {
  int ans = 0;
  int i2;
  for(int i = 5; i <= n; i += 5){
    i2 = i;
    while(i2 % 5 == 0) {
      ans++;
      i2 /= 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) {
      return cautbin5(from, mid, p);
    } else {
      return cautbin5(mid + 1, to, p);
    }
  }
}

int main() {//cautbin5
  int p;
  in >> p;
  out << cautbin5(1, p * 5 + 1, p);
  return 0;
}