Pagini recente » Cod sursa (job #965864) | Clasament pregatire_pt_oji | Cod sursa (job #3126218) | Cod sursa (job #542978) | Cod sursa (job #645640)
Cod sursa(job #645640)
#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 = 100000000;
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;
}