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<cstdio>
int main()
{long long int n;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
long long int sum=1%10,k=n%10;
while(n>0)
{
if(n%2==1)
sum=sum*k%10;
k=k*k%10;
n/=2;
}
printf("%d\n",sum);
}
return 0;
}