hd acm1061
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1[4]={0,1,5,6};
int num2[4][4]={{4,8,6,2},{9,7,1,3},
{9,3,1,7},{4,2,6,8}};
int num3[2][2]={{6,4},{1,9}};
int n,i,rea,j;
long x,y;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%ld",&x);
rea=x%10;
for(j=0;j<4;j++){
if(num1[j]==rea){
printf("%d\n",num1[j]);
rea=0;
break;
}
}
if(rea){
if(rea==2){
y=(x-1)%4-1;
printf("%d\n",num2[0][y]);
}
if(rea==3){
if((x-1)%4==0) y=3;
else y=(x-1)%4-1;
printf("%d\n",num2[1][y]);
}
if(rea==7){
if((x-1)%4==0) y=3;
else y=(x-1)%4-1;
printf("%d\n",num2[2][y]);
}
if(rea==8){
y=(x-1)%4-1;
printf("%d\n",num2[3][y]);
}
if(rea==4){
y=(x-1)%2-1;;
printf("%d\n",num3[0][y]);
}
if(rea==9){
if((x-1)%2==0) y=1;
else y=(x-1)%2-1;
printf("%d\n",num3[1][y]);
}
}
}
return 0;
}