Pagini recente » Cod sursa (job #522347) | Cod sursa (job #1987971) | Cod sursa (job #1106311) | Cod sursa (job #2276573) | Cod sursa (job #1249262)
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
const int RMAX = (1<<29);
int N,P;
int FCT( int nr ) {
int R= 0, step= 5;
while( step <= nr ) {
R+= nr/step;
step*= 5;
}
return R;
}
int Bin_search( int val ) {
int step= 1;
step= RMAX;
int i= 0;
for( ; step; step>>= 1 ) {
if( i+step <= RMAX && FCT(i+step)<val ) {
i+= step;
}
}
return i+1;
}
int main() {
in >> N;
int sol= Bin_search( N );
if( FCT(sol) == N ) out << sol;
else out << "-1";
out << '\n';
return 0;
}