Pagini recente » Cod sursa (job #702092) | Cod sursa (job #773265) | Cod sursa (job #2205964) | Cod sursa (job #233450) | Cod sursa (job #2370853)
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
long long k,st,dr,mij,ok,prod,cmij,s,cif;
int main()
{
in>>cif;
if (cif==0)
out << 1;
else {
st=5;
dr=400000015;
while (st<=dr) {
mij=(st+dr)/2;
prod=5;
cmij=mij;
s=0;
while (cmij/prod!=0) {
s+=cmij/prod;
prod*=5;
}
if (s==cif) {
ok=1;
break;
}
else if (s<cif)
st=mij+1;
else
dr=mij-1;
}
if (ok==1)
out<<mij-mij%5;
else
out<< -1;
}
return 0;
}