Pagini recente » Cod sursa (job #817249) | Cod sursa (job #11943) | Cod sursa (job #1874768) | Cod sursa (job #2790952) | Cod sursa (job #285720)
Cod sursa(job #285720)
#include<stdio.h>
#include<math.h>
//#include<conio.h>
long put(long x)
{
long k=0;
while(x%5==0) { k++; x/=5; }
return k;
}
int main()
{
//clrscr();
long ok=1,t,r,p,i,t1,t2,k1,k2=0,k;
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%ld",&p);
if(p==0) printf("1");
else{
for(i=1; k2<p; i++)
{
k2=(pow(5,i)-1)/4;
t2=pow(5,i);
}
if(k2==p) printf("%ld",t2);
else{
t1=t2/5;
k1=(pow(5,put(t1))-1)/4;
if(p>(k1+k2)/2)
{
k=t2+5;
while(k2>=p)
{
k-=5; t=k;
while(t%5==0)
while(k2>=p) { t/=5; k2--; }
if(k2<p) ok=0;
}
}
else
{
k=t1;
while(k1<p)
{
k+=5;
k1+=put(k);
}
}
if (ok) printf("%ld",k);
else printf("-1");}}
return 0;
}