Cod sursa(job #2520201)

Utilizator andreic06Andrei Calota andreic06 Data 9 ianuarie 2020 11:06:14
Problema Factorial Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>

using namespace std;


ifstream fin ( "fact.in" );
ofstream fout ( "fact.out" );
const int NMAX = 1e8;
const int P = 5;

int main()
{

   int n, st, dr;
   int x, res;
   int f0, pwr;

   fin >> n;

   st = 1;
   dr = NMAX;

   while ( st <= dr ){

      x = st + ( dr - st ) / 2;

      f0 = 0;
      pwr = 1;
      while ( pwr <= x ){
         pwr *= P; /// ar fi trebuit sa aleg min, dar stiu sigur ca cu 5 e min
         f0 += ( x / pwr );
      }

      if ( f0 == n ){
        dr = x - 1;
        res = x;
      }
      else if ( f0 < n )
        st = x + 1;
      else
        dr = x - 1;
   }

   fout << res;
    return 0;
}