题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1061
题意:t组样例,输入n,输出n^n的个位是多少。
代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define closeio std::ios::sync_with_stdio(false)
#define Mod 10
ll pow(ll a,ll b)
{
ll res=1;
while(b!=0)
{
if(b%2==1)
res=res*a%Mod;
a=a*a%Mod;
b/=2;
}
return res;
}
int main()
{
ll t,n,x;
cin>>t;
while(t--)
{
cin>>n;
x=pow(n,n)%Mod;
cout<<x<<endl;
}
return 0;
}