#include <iostream>
using namespace std;
int main(){
long long int a,b;
while(cin>>a>>b){
if(a==0&&b==0)break;
else if(b==0)cout<<"1"<<endl;
else if(a%10==0)cout<<"0"<<endl;
else if(a%10==1)cout<<"1"<<endl;
else if(a%10==2){
if(b%4==1)cout<<"2"<<endl;
else if(b%4==2)cout<<"4"<<endl;
else if(b%4==3)cout<<"8"<<endl;
else if(b%4==0)cout<<"6"<<endl;
}
else if(a%10==3){
if(b%4==1)cout<<"3"<<endl;
else if(b%4==2)cout<<"9"<<endl;
else if(b%4==3)cout<<"7"<<endl;
else if(b%4==0)cout<<"1"<<endl;
}
else if(a%10==4){
if(b%2==1)cout<<"4"<<endl;
else if(b%2==0)cout<<"6"<<endl;
}
else if(a%10==5)cout<<"5"<<endl;
else if(a%10==6)cout<<"6"<<endl;
else if(a%10==7){
if(b%4==1)cout<<"7"<<endl;
else if(b%4==2)cout<<"9"<<endl;
else if(b%4==3)cout<<"3"<<endl;
else if(b%4==0)cout<<"1"<<endl;
}
else if(a%10==8){
if(b%4==1)cout<<"8"<<endl;
else if(b%4==2)cout<<"4"<<endl;
else if(b%4==3)cout<<"2"<<endl;
else if(b%4==0)cout<<"6"<<endl;
}
else if(a%10==9){
if(b%2==1)cout<<"9"<<endl;
else if(b%2==0)cout<<"1"<<endl;
}
}
return 0;
}
幫忙看一下