Cod sursa(job #47680)

Utilizator alutzuAlexandru Stoica alutzu Data 3 aprilie 2007 21:58:09
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 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
            {

	      printf ( "%ld" , caut ( 1 , 1000000000 ) );

            }


           fclose ( stdin );
           fclose ( stdout );

           return 0;

       }