Pagini recente » Cod sursa (job #3177685) | Cod sursa (job #706205) | Cod sursa (job #2947081) | Cod sursa (job #2873738) | Cod sursa (job #460674)
Cod sursa(job #460674)
#include <iostream>
#include <fstream>
using namespace std ;
ifstream f ( "fact.in" ) ;
ofstream g ("fact.out" ) ;
int tintaImpusa ;
int nrZerouri ( int Numar , int Putere )
{
if ( Putere > Numar )
return 0 ;
return Numar / Putere + nrZerouri ( Numar , Putere * 5 ) ;
}
int main ( )
{
f >> tintaImpusa ;
int Left = 0 , Right = 1e+9 ;
int Mid = ( Left + Right ) / 2 ;
while ( Left != Mid )
{
if ( nrZerouri ( Mid , 5 ) > tintaImpusa )
{
Right = Mid ;
Mid = ( Left + Right ) / 2 ;
continue ;
}
if ( nrZerouri ( Mid , 5 ) < tintaImpusa )
{
Left = Mid ;
Mid = ( Left + Right ) / 2 ;
continue ;
}
if ( nrZerouri ( Mid , 5 ) == tintaImpusa )
break ;
}
while ( Mid % 5 != 0 )
Mid -- ;
if ( tintaImpusa == 0 )
{
g << 1 << endl ;
return 0 ;
}
if ( nrZerouri ( Mid , 5 ) != tintaImpusa )
{
g << -1 << endl ;
return 0 ;
}
g << Mid ;
return 0 ;
}