Pagini recente » Cod sursa (job #1786067) | Cod sursa (job #2335960) | Cod sursa (job #658415) | Cod sursa (job #630052) | Cod sursa (job #1358216)
# include <fstream>
# define MAXIM 100000000
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int n;
int fact(int x)
{
int nr=0,p=5;
while (x>=p)
{
nr+=x/p;
p*=5;
}
return nr;
}
int caut(int p,int u,int x)
{
int nr,mij;
if (p>=u) return p;
mij=(p+u)/2;
nr=fact(mij);
if (nr==n) return mij;
if (nr<x) return caut(mij+1,u,x);
else return caut(p,mij-1,x);
}
int main()
{
int ras,rez;
in>>n;
if (n==0) out<<1;
else
{
rez=caut(1,MAXIM,n);
if (fact(rez)==n)
{
while (rez%5) rez--;
out<<rez;
}
else out<<-1;
}
return 0;
}