Cod sursa(job #667509)

Utilizator gugianghel liviu gugi Data 23 ianuarie 2012 11:43:36
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
#define 1 1000000000
using namespace std;
ifstream f ( "fact.in" );
ofstream g ( "fact.out" );
long long p,ok,poz,i,I;

long long OK ( int val )
{
 long long  X=val, cif=0,C;
 for ( C=5; C<=val; C*=5 )
 cif+=X/C;

 return cif;
 }
 long long caut ( int PE )
 {
 long long step=1,p=0;
 for ( ; step<=1; step*=2 );

 for ( ; step; step/=2 )
 if ( OK ( p+step ) <= PE ) p+=step;
 return p;
 }
 int main()
 {  f>> p;
   poz=caut ( p -1 );
  if (p==0) g<<1;
  else
  {
  for ( i=poz; i<=poz+5&&ok==0; i++ )
  {
   I=i;
   if ( OK ( I ) ==p ) {
   g<<I;
   ok=1;
   continue;
      }
   }
   if ( ok==0 ) g<<-1;
   }
   f.close();
   g.close();
   return 0;
   }