#include <cstdio>
int main()
{
int N,m2,m5,b,k,i;
while(scanf("%d",&N)==1)
{
if(N==1||N==0)
{
printf("%5d -> %d\n",N,1);
continue;
}
m2=0;
m5=0;
b=1;
for(i=1;i<=N;++i)
{
k=i;
while(k%2==0)
{
m2++;
k/=2;
}
while(k%5==0)
{
m5++;
k/=5;
}
b=(b*k)%10;
}
m2-=m5;
switch(m2%4)
{
case 0:
b=(b*6)%10;
break;
case 1:
b=(b*2)%10;
break;
case 2:
b=(b*4)%10;
break;
default:
b=(b*8)%10;
}
printf("%5d -> %d\n",N,b);
}
return 0;
}
哈哈哈
还是我给出最帅的算法吧!