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.
题意:快速求出n^n的个位数字。
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
long int i,j,k,s,t,d;
scanf("%ld",&i);
while(i--)
{
scanf("%ld",&j);
int d=1%10,t=j%10;
while(j)
{
if(j&1)
d=(d*t)%10;
j/=2;
t=(t*t)%10;
}
printf("%ld\n",d);
}
return 0;
}