求n^n的个位
Sample Input
2
3
4
Sample Output
7
6
直接快速幂了,注意要用long long
#include<cstdio>
long long quick_mod(long long a,long long b,long long m) {
long long ans = ;
while (b) {
if (b&) {
ans = (ans * a) % m;
b--;
}
b/=;
a = a * a% m;
}
return ans;
}
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("%lld\n",quick_mod(n,n,));
}
return ;
}