#include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main(void) { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); if (m == 1 && t[m - 1] == '0') { cout << 1 << endl; return 0; } int tmp = s[n - 1] - '0'; int num; if (m == 1) num = t[m - 1] - '0'; else if (m == 2) num = (t[m - 2] - '0') * 10 + (t[m - 1] - '0'); else num = (t[m - 3] - '0') * 100 + (t[m - 2] - '0') * 10 + (t[m - 1] - '0'); num %= 4; num = (num + 3) % 4; //cout << tmp << " " << num << endl; int ababa = tmp; for (int i = 0; i < num; ++i) { ababa = (ababa * tmp) % 10; } cout << ababa << endl; return 0; }