Pagini recente » Cod sursa (job #285441) | Cod sursa (job #68774) | Cod sursa (job #1120581) | Cod sursa (job #2438642) | Cod sursa (job #645653)
Cod sursa(job #645653)
#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 = 4 * p;
int b = 6 * p;
int c = 0;
int zeros;
if( p == 0 ) return 1;
while( a < b ) {
c = ( b + a ) / 2;
zeros = trailing_zeros( c );
if( zeros == p ) return ( c - c % 5 );
if( zeros > p ) b = c;
else a = c + 1;
}
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;
}