#include #include #include using namespace std; int main() { string n, m; cin >> n >> m; if (count(m.begin(), m.end(), '0') == m.size()) { cout << 1 << endl; return 0; } static int lsd[10][4]; // [n][m] for (int n = 0; n < 10; ++n) { lsd[n][0] = 1; for (int m = 1; m < 4; ++m) { lsd[n][m % 4] = lsd[n][m - 1] * n % 10; } } int ls2dM = (m.size() >= 2 ? (m[m.size() - 2] - '0') : 0) * 10 + (m[m.size() - 1] - '0'); cout << lsd[(n.back() - '0')][ls2dM % 4] << endl; return 0; }