Pagini recente » Cod sursa (job #733644) | Cod sursa (job #1740497) | Cod sursa (job #68173) | Cod sursa (job #224579) | Cod sursa (job #2166703)
#include <iostream>
#include<fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int st,dr,x,p,mij,d,aux,cont;
long long s;
int main()
{
in>>p;
st=1;
dr=1000000000;
while(st<dr)
{
mij=(st+dr)/2;
x=mij;
s=0;
while(x)
{
s=s+x/5;
x/=5;
}
if(s>=p)
dr=mij;else st=mij+1;
}
aux=dr;
d=5;
while(aux/d>0)
{
cont+=aux/d;
d*=5;
}
if(cont!=p)
out<<-1;
else
out<<dr;
return 0;
}