#include #include #include using namespace std; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); string n, m; cin >> n >> m; int nn = *(--n.end()) - '0'; int mn; if (m.size() == 1) { if (m.at(0) == '0') { cout << "1" << endl; return 0; } mn = *(--m.end()) - '0'; } else { mn = *(--m.end()) - '0' + 10 * (*(m.end() -2) - '0'); } vector> hitoketame{{0,0,0,0}, {1,1,1,1}, {6,2,4,8}, {1,3,9,7}, {6,4,6,4}, {5,5,5,5}, {6,6,6,6}, {1,7,9,3}, {6,8,4,2}, {1,9,1,9}}; // mの下位一or二ケタmnと、3(2進法で11)の&をとって、 // 00ならhitoketame[?][0]、01ならhitoketame[?][1]、 // 10ならhitoketame[?][2]、11ならhitoketame[?][3] // ?は n mod10 = nnの値 if ((mn & 3) == 0) { cout << hitoketame[nn][0] << endl; } else if ((mn & 3) == 1) { cout << hitoketame[nn][1] << endl; } else if ((mn & 3) == 2) { cout << hitoketame[nn][2] << endl; } else { cout << hitoketame[nn][3] << endl; } return 0; }