Cod sursa(job #113112)

Utilizator SharpeBigadrian ursulescu SharpeBig Data 8 decembrie 2007 20:04:31
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <fstream>
using namespace std;
  
   ifstream fin("fact.in");
   ofstream fout("fact.out");
   int dami(int n)
   {  int rez=0;
      while(n>0) rez+=(n=n/5);
      return rez;
   }
   int tmp,p,juma,lo,hi,rez=1000000001;
  
int main()
{ fin>>p;
  lo=1;hi=rez-1;
  while(lo<hi)
  {  juma=(lo+hi)/2;
     tmp=dami(juma);
     if(tmp<p) lo=juma+1; else
     {  if(tmp==p&&rez>juma) rez=juma;
        hi=juma;
     }                                
  } 
  if (rez==1000000001) rez=-1;
  fout<<rez;fout.close();fin.close();
  return 0;   
}