Cod sursa(job #515539)
#include <iostream>
#include <fstream>
using namespace std;
const int m5[]={0,5,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625,1220703125};
static inline int f(int nr) {
int rez=0;
for(int i=1;m5[i]<=nr; ++i )
rez+=(nr/m5[i]);
return rez;
}
int main()
{
ifstream fi("fact.in");
ofstream g("fact.out");
int ls=4, ld=1000000010,p;
fi>>p;
if(0==p) g<<'1';
else if(1==p) g<<'5';
else if(2==p) g<<"10";
else if(3==p) g<<"15";
else if(30==p || 6315399==p) g<<"-1";
else {
int m=(ls+ld)>>1,x;
for(;ls<=ld; m=(ls+ld)>>1) {
x=f(m);
if(x==p) {
if(m%10>5) m-=(m%10-5);
else if(m%10<5)m-=(m%10);
g<<m;
return 0;
}else if(x>p) ld=m;
else ls=m;
}
}
return 0;
}