Pagini recente » Cod sursa (job #3196551) | Cod sursa (job #1153510) | Cod sursa (job #2817676) | Cod sursa (job #1506107) | Cod sursa (job #629094)
Cod sursa(job #629094)
#include <fstream>
#define INF (1<<30)
using namespace std;
int P, Rez;
bool gasit;
ifstream in("fact.in");
ofstream out("fact.out");
inline int minim( int a, int b )
{
return (a<b) ? a : b;
}
inline int Nr0( int x )
{
int R = 0, Pow = 5;
while( x/Pow > 0 )
{
R += x/Pow;
Pow *= 5;
}
return R;
}
inline int BS( int St, int Dr )
{
if( St <= Dr )
{
int M = St + (Dr-St)/2;
if( Nr0( M ) == P && Nr0( M-1 ) < P ) return M;
else if( Nr0( M ) >= P ) return BS( St, M-1 );
else return BS( M+1, Dr );
}
else return -1;
}
int main()
{
in >> P;
out << BS( 1, INF ) << '\n';
return 0;
}