Pagini recente » Cod sursa (job #1679904) | Cod sursa (job #2777290) | Cod sursa (job #2809906) | Cod sursa (job #2978928) | Cod sursa (job #1563606)
#include <cstdio>
using namespace std;
const int MAX=2000000000;
int fact(int x);
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
int p;
scanf("%d",&p);
if(p==0)
{
printf("1\n");
return 0;
}
int st=1,dr=MAX,mid,prec;
bool ok=false;
while(st<=dr and !ok)
{
mid = st+(dr-st)/2;
prec=fact(mid);
if(prec==p)ok=true;
if(prec<p)st=mid+1;
else dr=mid-1;
}
if(ok)
{
while(mid%5)mid--;
printf("%d\n",mid);
}
else
printf("-1\n");
return 0;
}
int fact(int x)
{
int a=5,rez=0;
while(x/a)
{
rez+=x/a;
a*=5;
}
return rez;
}