#include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main(){ int n, m, i = 1, diff = 0, s = -1; cin >> n >> m; int r = n, m1 = m; vector modulo(11, -1); while(1){ r %= 10; for (int j = 1; j <= 10; j++){ if (modulo[j] == r){ diff = i -j; s = j; m1 -= j; m1 %= diff; m1 += j; if (diff == 1) cout << modulo[s] << endl; else cout << modulo[m1] << endl; return 0; } } modulo[i] = r; i++; r *= n; } }