131 lines
1.5 KiB
C++
131 lines
1.5 KiB
C++
#include<bits/stdc++.h>
|
||
using namespace std;
|
||
|
||
int main() {
|
||
int a,b;
|
||
cin>>a>>b;
|
||
//个位数
|
||
a=a%10;
|
||
if(b==0) {
|
||
cout<<1<<endl;
|
||
return 0;
|
||
}
|
||
// 0 1 5 6多少次方都是自己
|
||
if(a==0 || a==1 ||a==5 || a==6) {
|
||
cout<<a<<endl;
|
||
return 0;
|
||
}
|
||
//如果是2,那么按2 4 8 6循环
|
||
if(a==2) {
|
||
b=b%4;
|
||
if(b==1) {
|
||
cout<<2<<endl;
|
||
return 0;
|
||
}
|
||
if(b==2) {
|
||
cout<<4<<endl;
|
||
return 0;
|
||
}
|
||
if(b==3) {
|
||
cout<<8<<endl;
|
||
return 0;
|
||
}
|
||
if(b==0) {
|
||
cout<<6<<endl;
|
||
return 0;
|
||
}
|
||
}
|
||
//如果是3
|
||
if(a==3) {
|
||
b=b%4;
|
||
if(b==1) {
|
||
cout<<3<<endl;
|
||
return 0;
|
||
}
|
||
if(b==2) {
|
||
cout<<9<<endl;
|
||
return 0;
|
||
}
|
||
if(b==3) {
|
||
cout<<7<<endl;
|
||
return 0;
|
||
}
|
||
if(b==0) {
|
||
cout<<1<<endl;
|
||
return 0;
|
||
}
|
||
}
|
||
//如果是4
|
||
if(a==4) {
|
||
b=b%2;
|
||
if(b==1) {
|
||
cout<<4<<endl;
|
||
return 0;
|
||
}
|
||
if(b==0) {
|
||
cout<<6<<endl;
|
||
return 0;
|
||
}
|
||
}
|
||
//如果是7
|
||
if(a==7) {
|
||
b=b%4;
|
||
if(b==1) {
|
||
cout<<7<<endl;
|
||
return 0;
|
||
}
|
||
if(b==2) {
|
||
cout<<9<<endl;
|
||
return 0;
|
||
}
|
||
|
||
if(b==3) {
|
||
cout<<3<<endl;
|
||
return 0;
|
||
}
|
||
|
||
if(b==0) {
|
||
cout<<1<<endl;
|
||
return 0;
|
||
}
|
||
}
|
||
//如果是8
|
||
if(a==8) {
|
||
b=b%4;
|
||
if(b==1) {
|
||
cout<<8<<endl;
|
||
return 0;
|
||
}
|
||
if(b==2) {
|
||
cout<<4<<endl;
|
||
return 0;
|
||
}
|
||
|
||
if(b==3) {
|
||
cout<<2<<endl;
|
||
return 0;
|
||
}
|
||
|
||
if(b==0) {
|
||
cout<<6<<endl;
|
||
return 0;
|
||
}
|
||
}
|
||
|
||
//如果是9
|
||
if(a==9) {
|
||
b=b%2;
|
||
if(b==1) {
|
||
cout<<9<<endl;
|
||
return 0;
|
||
}
|
||
if(b==0) {
|
||
cout<<1<<endl;
|
||
return 0;
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
|