N^N对10取余即可
#include <iostream> #include <string.h> #include <algorithm> #include <stdio.h> #include <math.h> #include <map> #include <string> #include <set> #include <stack> #include<queue> using namespace std; #define forseach(i,j,n) for(int i=j;i<n;i++) #define debug freopen("in.txt","r",stdin),freopen("out.txt","w",stdout); #define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); //#define PI acos(-1) typedef long long ll; const int maxn = 1e5; ll mypow(ll &x,ll &y,int &mod) { ll ans=1; while(y) { if(y&1) ans=(x*ans)%mod; x=(x*x)%mod; y>>=1; } return ans; } int main() { //debug; ios; int T; ll x; cin>>T; while(T--) { cin>>x; ll y=x; int mod=10; cout<<mypow(x,y,mod)<<'\n'; } return 0; }