Pagini recente » Cod sursa (job #1292508) | Cod sursa (job #233735) | Cod sursa (job #1430618) | Cod sursa (job #713013) | Cod sursa (job #1008250)
#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;
}
}
fout<<sol<<"\n";
return 0;
}