Pagini recente » Cod sursa (job #1091918) | Cod sursa (job #2365930) | Istoria paginii utilizator/commercialgas686 | Cod sursa (job #2183874) | Cod sursa (job #1448152)
#include <fstream>
#define NMax 1000000000
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int fact (int x)
{
int a=5,rez=0;
while (x/a)
{
rez=rez+x/a;
a=a*5;
}
return rez;
}
int main ()
{
int p,val;
in>>p;
if (p==0) g<<1;
else
{
int min=1,max=NMax,mij;
int ok=0;
while (min<=max && !ok)
{
mij=(min+max)/2;
val=fact(mij);
if (val<p) min=mij+1;
else if (val>p) max=mij-1;
else ok=1;
}
if (ok)
{
while (mij%5) mij--;
out<<mij;
}
else out<<-1;
}
return 0;
}