Pagini recente » Cod sursa (job #2943754) | Cod sursa (job #2233179) | Cod sursa (job #500682) | Cod sursa (job #117338) | Cod sursa (job #1004276)
#include<stdio.h>
long long q,p,st,dr,m,x;
long long putere(long long x)
{
if(x==0)return 0;
return x/5+putere(x/5) ;
}
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%lld",&p);
if(p==0){printf("1\n");return 0;}
st=0;
dr=20000000;
while(st!=dr)
{
m=(st+dr)/2;
x=putere(m);
if(p==x)
{
while(m%5!=0)--m;
printf("%lld\n",m);
return 0;
}
else
if(p>x)st=m+1;
else
if(p<x)dr=m;
}
m=st;
while(m%5!=0)--m;
if(putere(m)==p){printf("%d\n",m);return 0;}
printf("-1\n");
return 0;
}