http://acm.hdu.edu.cn/showproblem.php?pid=1061
题意:求N的N次方是多少。
题解:
(a*b)%m=((a%m)*(b%m))%m
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod(ll a,ll b)
{
if(b==1)return a;
ll s=mod(a,b/2)%10;
if(b%2==0)return (s*s)%10;
else return (s*s*a)%10;
}
int main()
{
int n;
ll temp;
scanf("%d",&n);
while(n--)
{
scanf("%lld",&temp);
ll ans=mod(temp,temp);
printf("%lld\n",ans);
}
return 0;
}