题目描述
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>
int main()
{
long long int POW(long long int,long long int);
int T,i;
long long int s,n;
int r;
scanf("%d",&T);
for (i=1;i<=T;i++)
{
s=1;
scanf("%d",&n);
s=POW(n,n);
printf("%lldn",s);
}
return 0;
}
long long int POW(long long int a,long long int b)
{ long long int s=1,i;
while(b!=0)
{
if(b&1!=0)
s=s*a;
s=s%10;
a=a*a%10;
b>>=1;
}
return s;
}
解析
暂无