打表大法好
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;
const int MAX = 3600*24;
int main()
{
int a,b;
int s[10][4]={{0,0,0,0},{1,1,1,1},{2,4,8,6},{3,9,7,1},{4,6,4,6},{5,5,5,5},{6,6,6,6},{7,9,3,1},{8,4,2,6},{9,1,9,1}};
while(cin>>a>>b)
{
cout<<s[a%10][(b-1)%4]<<endl;
}
return 0;
}