Pagini recente » Cod sursa (job #2241471) | Cod sursa (job #2569666) | Cod sursa (job #268788) | Cod sursa (job #1347051) | Cod sursa (job #645639)
Cod sursa(job #645639)
#include <fstream>
using namespace std;
int trailing_zeros( int n ) {
int result = 0;
int power = 5;
while( n / power >= 1 ) {
result += n / power;
power *= 5;
}
return result;
}
int solve( int p ) {
int a = 0;
int b = 5 * p;
int c = -1;
int zeros;
while( a < b && a != c && b != c ) {
c = ( b + a ) / 2;
zeros = trailing_zeros( c );
if( zeros == p ) return c;
if( zeros > p ) b = c;
else a = c;
}
return -1;
}
int main() {
int p;
fstream f( "fact.in", ios::in );
f >> p;
fstream g( "fact.out", ios::out );
g << solve( p );
return 0;
}