题目链接: 1061 ( Rightmost Digit )
/**
* hdu1061 Rightmost Digit(快速幂取模)
*
*/
#include <iostream>
using namespace std;
typedef long long LL;
LL fastPow(LL a, LL b, LL mod = LLONG_MAX)
{
a %= mod;
LL t = 1;
while (b) {
if (b&1) t = t*a%mod;
a = a*a%mod;
b >>= 1;
}
return t%mod;
}
int main()
{
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
cout << fastPow(n, n, 10) << endl;
}
return 0;
}