Pagini recente » Cod sursa (job #2636964) | Cod sursa (job #2699217) | Cod sursa (job #83707) | Cod sursa (job #1978075) | Cod sursa (job #39659)
Cod sursa(job #39659)
#include<stdio.h>
#include<math.h>
long s,a,i,j,k,l,n,m,x[20];
int kkt(long x)
{
long s,i,k;
i=5;
k=x;
s=0;
while (k/i>=1)
{
s+=k/i;
i=i*5;
}
if (s==n) return 1;
return 0;
}
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%ld",&n);
x[0]=0;
x[1]=25;
x[2]=125;
x[3]=625;
for (i=4;i<=13;i++)
{
x[i]=pow(5,i+1)-pow(5,i)+5;
}
m=5;
if (n>pow(5,m))
{
s=1;
while(n>pow(5,m))
m++;
}
else
{
s=0;
while(n<pow(5,m))
m--;
}
if (x[m]==n)
printf("%ld\n",pow(5,i+1));
else
{
if (s==1)
{
k=x[m-1];
/*
j=k;
for (i=k;j<=n;i+=5)
a=i;
while (a%5==0)
{
j++;
a=a/5;
}
printf("%ld\n",i);
*/
for (i=k;i<=x[m];i+=5)
if (kkt(i)) {printf("%ld\n",i); return 0;}
}
else
{
k=x[m];
/*j=k;
for (i=k;j<=n;i+=5)
{
a=i;
while (a%5==0)
{
j++;
a=a/5;
}
}
printf("%ld\n",i);
*/
for (i=k;i<=x[m+1];i+=5)
if (kkt(i)) {printf("%ld\n",i); return 0;}
}
}
return 0;
}