Given a positive integer N, you should output the most right digit of N^N.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
2 3 4
7
6
In the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7. In the second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6.
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int m,t,sum=1;
scanf("%d",&m);
t=m;
while(m)
{
if(m&1)
sum=(sum*t)%10;
t=(t%10)*(t%10);
m>>=1;
}
printf("%d\n",sum);
}
return 0;
}