快速幂取模
#include <iostream>
using namespace std;
typedef long long ll;
ll pow(ll a, ll b)
{
ll r = 1;
while (b)
{
if (b & 1)
{
r *= a;
r %= 10;
}
a *= a;
a %= 10;
b >>= 1;
}
return r;
}
int main()
{
ll n;
cin >> n;
ll res = pow(n,n);
cout << res % 10 << endl;
return 0;
}