HDU-1097
A hard puzzle
#include<stdio.h>
int main (void)
{
int a,b;
int p[10][10]={{0},{1},{6,2,4,8},{1,3,9,7},{6,4},{5},{6},{1,7,9,3},{6,8,4,2},{1,9}};
while(scanf("%d %d",&a,&b)==2){
if(b==0) printf("1\n");
else {
a%=10;
if(a==0||a==1||a==5||a==6)
printf("%d\n",a);
else if(a==4||a==9)
printf("%d\n",p[a][b%2]);
else
printf("%d\n",p[a][b%4]);
}
}
return 0;
}