题目描述
Given a positive integer N, you should output the most right digit of N^N.
?
输入
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
?
输出
For each test case, you should output the rightmost digit of N^N.
?
样例输入
2
3
4
样例输出
7
6
我的代码:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int t,i,a[5];
int n,count;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
scanf("%d",&n);
count=n;
n=n%10;
if(n==1)n=1;
else if(n==0)n=0;
else if(n==5)n=5;
else if(n==6)n=6;
else if(n==2){
a[0]=6;a[1]=2;a[2]=4;a[3]=8;
count=count%4;
n=a[count];
}
else if(n==3){
a[0]=1;a[1]=3;a[2]=9;a[3]=7;
count=count%4;
n=a[count];
}
else if(n==7){
a[0]=1;a[1]=7;a[2]=9;a[3]=3;
count=count%4;
n=a[count];
}
else if(n==4){
a[0]=6;a[1]=4;
count=count%2;
n=a[count];
}
else if(n==8){
a[0]=6;a[1]=8;a[2]=4;a[3]=2;
count=count%4;
n=a[count];
}
else if(n==9){
a[0]=1;a[1]=9;
count=count%2;
n=a[count];
}
printf("%d\n",n);
}
return 0;
}