#include #include #include // 一桁の数 n が何乗するとループするか int calc_loop_count(int n) { for (int i = 2; i < 100; i++) { int num = std::pow(n, i); if (num % 10 == n) { return i; } } return 1; } int remainder(int n, std::string p) { int ans = 1; for (int i = 0; !p.empty(); i++) { int val = p.back() - '0'; p.pop_back(); int loop = pow(10, i); for (int j = 0; j < loop; j++) { int mul = pow(n, val); ans = (ans * mul) % 10; } } return ans; } int main() { std::string n, m; std::cin >> n >> m; int num = n.back() - '0'; // 最後の一桁を取り出す int loop_count = calc_loop_count(num); std::cout << remainder(num, m) << std::endl; return 0; }