Pagini recente » Cod sursa (job #1498833) | Cod sursa (job #2053205) | Cod sursa (job #1907141) | Cod sursa (job #2933345) | Cod sursa (job #3142145)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p,l,r,m,e,x,s;
bool ok=1;
int main()
{
fin>>p;
l=1;
r=100000005;
if (p==0) {
fout<<1;
}
else {
while (l<=r && ok) {
m=(l+r)/2;
e=0;
x=m;
while (x>0) {
e+=x;
x/=5;
}
if (e<p) {
l=m+1;
}
else if (e>p) {
r=m-1;
}
else {
ok=0;
s=m*5;
}
}
if (ok)
fout<<-1;
else fout<<s;
}
return 0;
}