Cod sursa(job #47688)

Utilizator alutzuAlexandru Stoica alutzu Data 3 aprilie 2007 22:02:36
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include<stdio.h>

long p;

long nrz ( long x )
      {


         long p = 5 , m = 0;

         while ( x / p )
              {

                  m += ( x / p );
                  p *= 5;

              }

         return m;


      }


long caut ( long x , long y )
      {


        if ( x > y )
           return -1;

        long mij , nr ;

        mij = ( x + y ) / 2;

        nr = nrz ( mij );

        if ( nr  > p )
           caut ( x , mij - 1 );

        else

           if ( nr < p )
            caut ( mij + 1 , y );

           else

              //sunt egale
              return mij;

      }

int main ( )
       {


           freopen ( "fact.in" , "r" , stdin );
           freopen ( "fact.out" , "w" , stdout );


           scanf ( "%ld" , & p );

           if ( p == 0 )
             printf ( "1" );

           else
            {

	      long nr = caut ( 1 , 1000000000 ) ;
	      printf ( "%ld" ,  nr - nr % 5 );

            }


           fclose ( stdin );
           fclose ( stdout );

           return 0;

       }