Pagini recente » Cod sursa (job #2169379) | Cod sursa (job #3140244) | Cod sursa (job #672843) | Cod sursa (job #2353668) | Cod sursa (job #2832238)
#include <fstream>
#define MAXN 500000000
using namespace std;
ifstream fin( "fact.in" );
ofstream fout( "fact.out" );
int p5( int n ){
int e = 0, p = 5;
while( p < n )
e += ( n / p ), p *= 5;
return e;
}
int main(){
int p, st, dr, gasit = 0, mij;
fin >> p;
if( p == 0 )
fout << "1", gasit = 1;
st = 1, dr = MAXN + 1;
while( dr - st > 1 && !gasit ){
mij = (st + dr) / 2;
if( p5(mij) == p )
fout << (mij / 5) * 5, gasit = 1;
else{
if( p5(mij) < p )
st = mij + 1;
else
dr = mij - 1;
}
}
if( gasit == 0 )
fout << -1;
return 0;
}