Cod sursa(job #2070842)

Utilizator darkviper17Dark Viper darkviper17 Data 19 noiembrie 2017 22:48:33
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int L=21;

int zero(int x)
{
  int nrzero=0;
  
  while(x >= 5)
  {
    nrzero += x / 5;
      x /= 5;
  }
    return nrzero;
}

int binary_search(int x)
{
  int pas, r=0;
    pas = 1 << L;
  
  while(pas)
  {
    if(zero(r + pas) < x) r += pas;
      pas /= 2;
  }
  
  return r + 1;
}

int main()
{
  int n, sol;
  fin >> n;
    
    sol = binary_search(n);
    
    if( zero(sol) != n) 
        fout << -1;
      
     else fout << sol;
}