Pagini recente » Cod sursa (job #1974945) | Formatare Textile | Cod sursa (job #2078724) | Cod sursa (job #583852) | Cod sursa (job #690846)
Cod sursa(job #690846)
#include<stdio.h>
using namespace std;
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
long x,i,j,ok,Pr,p,k,m;
scanf("%ld",&p);
if(p==0){printf("1");return 0;}
i=0;j=p*15;ok=0;
while(i<=j&&ok==0)
{
m=(i+j)/2;
Pr=5;k=0;
while(Pr<m)
{
k=k+m/Pr;
Pr*=5;
}
if(k==p){x=m-m%5;ok=1;}
else if(k<p) i=m+1;
else j=m-1;
}
if(ok) printf("%ld",x);
else printf("-1");
return 0;
}