Pagini recente » Cod sursa (job #1624798) | Cod sursa (job #2370185) | Cod sursa (job #308451) | Cod sursa (job #57865) | Cod sursa (job #1008251)
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
const int pmax= 100000000;
const int sol_max= 5*pmax;
const int n5max= 14; //smallest x such as x>=sol_max and x power of 5
int f[n5max];
int check ( int x )
{
int sol= 0;
for ( int i= 1; i<n5max; ++i ) {
sol+= x/f[i];
}
return sol;
}
int main()
{
int p;
fin>>p;
f[0]=1;
for ( int i= 1; i<n5max; ++i ) {
f[i]= f[i-1]*5;
}
int step;
for ( step= 1; step<p*5; step*= 2 ) {
}
int sol;
for ( sol= max(p*5, 1); step>0; step/=2 ) {
if ( sol-step>0 && check(sol-step)>=p ) {
sol-= step;
}
}
if ( check(sol)!=p ) {
sol=-1;
}
fout<<sol<<"\n";
return 0;
}