Pagini recente » Cod sursa (job #2242834) | Cod sursa (job #609701) | Cod sursa (job #145241) | Cod sursa (job #1600591) | Cod sursa (job #2524300)
#include <fstream>
#include <algorithm>
using namespace std;
int nr_zero(int n)
{
int nr=0;
while(n>=5)
{
nr+=(n/=5);
}
return nr;
}
ifstream fin("fact.in");
ofstream fout("fact.out");
long long p,st,dr,m;
int main(int argc,const char *argv[])
{
fin>>p;
st=1;
dr=5e8;
while(st<dr)
{
m=(st+dr)/2;
if(nr_zero(m)>=p)
dr=m;
else if (nr_zero(m)<p)
st=m+1;
}
if(nr_zero(st)==p)
fout<<st;
else
fout<<-1;
return 0;
}