Pagini recente » Cod sursa (job #2975723) | Cod sursa (job #90565) | Cod sursa (job #592547) | Cod sursa (job #2782200) | Cod sursa (job #645651)
Cod sursa(job #645651)
#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 = 500000000;
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;
}