#include "bits/stdc++.h" using namespace std; //諸機能 #pragma region MACRO #define ANSWER(x) cerr << "answer: "; cout << (x) << endl #define DOUBLE_ANSWER(x) cerr << "answer: "; cout << set_presicion(10) << (x) << endl #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define ALL(a) begin((a)),end((a)) #define FILL(a,n) for(auto &hoge : (a)) hoge = (n) #define FILL_NDIM_ARRAY(arr,size,val) fill(*(arr),(*(arr) + (size)),(val)) #define mp make_pair #define EXIST(container, n) ((container).find((n)) != (container).end()) #define STOI(s,i,l) stoi(SUBSTR(s,i,l)) #define SUBSTR(s,i,l) string((s), (i), (l)) #define TGET(source,i) get((source)) #define NPI_TO_RAD(x) (180.0*x/PI) #define RAD_TO_NPI(x) (PI/180.0*x) #pragma endregion //デバッグなどの支援 #pragma region CODING_SUPPORT #define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; } #define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); } #define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); } #define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); } #pragma endregion //typedef(書き換える、書き足す可能性ある) #pragma region TYPE_DEF typedef long long ll; typedef pair pii; typedef pair pss; typedef pairpis; typedef pairpsi; typedef vector vs; typedef vector vi; #pragma endregion //諸々の定数(書き換える可能性ある) #pragma region CONST_VAL #define PI (2*acos(0.0)) #define EPS (1e-9) #define MOD (1e9 + 7) #pragma endregion //諸機能 #pragma region MACRO #define ANSWER(x) cerr << "answer: "; cout << (x) << endl #define DOUBLE_ANSWER(x) cerr << "answer: "; cout << set_presicion(10) << (x) << endl #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define ALL(a) begin((a)),end((a)) #define FILL(a,n) for(auto &hoge : (a)) hoge = (n) #define FILL_NDIM_ARRAY(arr,size,val) fill(*(arr),(*(arr) + (size)),(val)) #define mp make_pair #define EXIST(container, n) ((container).find((n)) != (container).end()) #define STOI(s,i,l) stoi(SUBSTR(s,i,l)) #define SUBSTR(s,i,l) string((s), (i), (l)) #define TGET(source,i) get((source)) #define NPI_TO_RAD(x) (180.0*x/PI) #define RAD_TO_NPI(x) (PI/180.0*x) #pragma endregion //デバッグなどの支援 #pragma region CODING_SUPPORT #define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; } #define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); } #define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); } #define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); } #pragma endregion //typedef(書き換える、書き足す可能性ある) #pragma region TYPE_DEF typedef long long ll; typedef pair pii; typedef pair pss; typedef pairpis; typedef pairpsi; typedef vector vs; typedef vector vi; #pragma endregion //諸々の定数(書き換える可能性ある) #pragma region CONST_VAL #define PI (2*acos(0.0)) #define EPS (1e-9) #define MOD (1e9 + 7) #pragma endregion int main() { string ns, ms; cin >> ns >> ms; int n, m = 0; n = STOI(ns,ns.length()-1,1); int t[] = {1,1,4,4,2,1,1,4,4,2}; int tmp = 0; rep(i, ms.length()) { m += ms[i] - '0'; m %= t[n]; m *= 10; } m /= 10; m = (m + 4 - 1 )% t[n]; if (ms == "0") { ANSWER(1); return 0; } int ans = n; rep(i, m) { ans *= n; ans %= 10; } ANSWER(ans); return 0; }