Pagini recente » Cod sursa (job #3230405) | Cod sursa (job #1007695) | Cod sursa (job #1931920) | Cod sursa (job #677015) | Cod sursa (job #2808196)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int p,l,r,m,exp,x,sol;
bool ok=1;
int main()
{
fin>>p;
l=1;
r=100000000;
if (p==0)
fout<<'1';
else
{
while (l<=r && ok)
{
m=(l+r)/2;
exp=0;
x=m;
while (x>0)
{
exp+=x;
x/=5;
}
if (exp<p)
{
l=m+1;
}
else if (exp>p)
{
r=m-1;
}
else
{
ok=0;
sol=m*5;
}
}
if (ok)
fout<<"-1";
else fout<<sol;
}
return 0;
}