Pagini recente » Cod sursa (job #693449) | Cod sursa (job #2726115) | Cod sursa (job #2249289) | Cod sursa (job #3250666) | Cod sursa (job #1087971)
#include <cstdio>
#define NMax 1000000000
using namespace std;
int fct (int x);
int main ()
{
int p,val;
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
if (p==0) printf("1");
else
{
int min=1,max=NMax,mid;
bool ok=false;
while (min<=max && !ok)
{
mid=(min+max)/2;
val=fct(mid);
if (val<p) min=mid+1;
else if (val>p) max=mid-1;
else ok=true;
}
if (ok)
{
while (mid%5) mid--;
printf("%d",mid);
}
else printf("-1");
}
}
int fct (int x)
{
int a=5,rez=0;
while (x/a)
{
rez=rez+x/a;
a=a*5;
}
return rez;
}