#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) std::cout<<(p)<>A>>B; int N,M; N = A[A.size()-1]-'0'; int Bsize = B.size(); int e[4] = {2,4,8,6}; int o[4] = {3,9,7,1}; if(Bsize == 1){ M = B[0]-'0'; }else{ M = (B[Bsize-2]-'0')*10+B[Bsize-1]-'0'; } if(Bsize == 1 && M == 0){//n^0 P(1); } else if(N==0 || N==1 || N==5 || N==6){ P(N); } else { if(N%2==0){ for(int i=0;i<4;++i){ if(N==e[i]){ P(e[ (M*(i+1)+3+i) % 4 ]); break; } } }else{ for(int i=0;i<4;++i){ if(N==o[i]){ P(o[ (M*(i+1)+3+i) % 4 ]); break; } } } } return 0; }