Cod sursa(job #2048368)

Utilizator theoioanaTheodoraD theoioana Data 25 octombrie 2017 22:59:24
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>

using namespace std;

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

int n, f[100000], st, dr, mid, p;

void fact( int x ){

         if( x==0 )
                  f[x]=0;
         else
                  for(int i=1; i<=x; i++){
                           int ii=i;
                           while( ii%5==0 ){
                                    f[x]++;
                                    ii/=5;
                           }
                  }
}



int main(){

         fin>>p;
         if( p== 0)
                  fout<<1;
         else{

                  st=0; dr=100000;

                  while( st<=dr ){
                           mid=(st+dr)/2;
                           fact(mid);
                           if( f[mid] >= p )
                                    dr=mid-1;
                           else
                                    st=mid+1;
                  }

                  fout<<st;
         }

return 0;
}