Pagini recente » Cod sursa (job #1121306) | Cod sursa (job #2035464) | Cod sursa (job #2123129) | Cod sursa (job #1577584)
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
const int nmax=100000000;
int zero(int x) {
int y=x,sol=0;
while (y/5!=0) {
sol=sol+y/5;
y=y/5;
}
return sol;
}
int main () {
int n;
fin>>n;
int n2;
for (n2=1; n2<=5*nmax; n2*=2) {
}
n2/=2;
int sol=5*nmax;
for (int step=n2; step>0; step/=2) {
if (sol-step>=1 && zero(sol-step)>=n) {
sol=sol-step;
}
}
if (zero(sol)==n) {
fout<<sol<<"\n";
} else {
fout<<"-1\n";
}
return 0;
}