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 t;
scanf("%d",&t);
while(t--)
{
long long n=0,i,m=1,b=0;
scanf("%lld",&n);
b=n;
n=n%10;
while(b>0)
{
if(b&1)
m=(m*n)%10;
b=b/2;
n=(n*n)%10;
}
printf("%lld\n",m);
}
}