#include<bits/stdc++.h>
using namespace std;
main()
{
string s,s1;
while(cin>>s>>s1)
{
long long a,l=s.size(),l1=s1.size(),k,k1,b=0,i,sum;
if(l==1&&l1==1&&s[0]=='0'&&s1[0]=='0')
{
break;
}
else if(s1[0]=='0'&&l1==1)
{
cout<<"1"<<endl;
continue;
}
a=s[l-1]-48;
long long remind=0;
for(i=0;i<l1;i++)
{
k=s1[i]-48;
remind=remind*10+k;
remind=remind%4;
}
//cout<<remind;
if(a==0||a==1||a==5||a==6)
cout<<a<<endl;
else if(a==4)
{
b=s1[l1-1]-48;
if(b%2==0)
{
cout<<"6"<<endl;
}
else
cout<<"4"<<endl;
}
else if(a==9)
{
b=s1[l1-1]-48;
if(b%2==0)
{
cout<<"1"<<endl;
}
else
cout<<"9"<<endl;
}
else if(a==2)
{
b=remind;
if(b==0)
{
cout<<"6"<<endl;
}
else if(b==1)
cout<<"2"<<endl;
else if(b==2)
cout<<"4"<<endl;
else if(b==3)
cout<<"8"<<endl;
}
else if(a==3)
{b=remind;
if(b==0)
{
cout<<"1"<<endl;
}
else if(b==1)
cout<<"3"<<endl;
else if(b==2)
cout<<"9"<<endl;
else if(b==3)
cout<<"7"<<endl;
}
else if(a==7)
{b=remind;
if(b==0)
{
cout<<"1"<<endl;
}
else if(b==1)
cout<<"7"<<endl;
else if(b==2)
cout<<"9"<<endl;
else if(b==3)
cout<<"3"<<endl;
}
else if(a==8)
{b=remind;
if(b==0)
{
cout<<"6"<<endl;
}
else if(b==1)
cout<<"8"<<endl;
else if(b==2)
cout<<"4"<<endl;
else if(b==3)
cout<<"2"<<endl;
}
}
}
using namespace std;
main()
{
string s,s1;
while(cin>>s>>s1)
{
long long a,l=s.size(),l1=s1.size(),k,k1,b=0,i,sum;
if(l==1&&l1==1&&s[0]=='0'&&s1[0]=='0')
{
break;
}
else if(s1[0]=='0'&&l1==1)
{
cout<<"1"<<endl;
continue;
}
a=s[l-1]-48;
long long remind=0;
for(i=0;i<l1;i++)
{
k=s1[i]-48;
remind=remind*10+k;
remind=remind%4;
}
//cout<<remind;
if(a==0||a==1||a==5||a==6)
cout<<a<<endl;
else if(a==4)
{
b=s1[l1-1]-48;
if(b%2==0)
{
cout<<"6"<<endl;
}
else
cout<<"4"<<endl;
}
else if(a==9)
{
b=s1[l1-1]-48;
if(b%2==0)
{
cout<<"1"<<endl;
}
else
cout<<"9"<<endl;
}
else if(a==2)
{
b=remind;
if(b==0)
{
cout<<"6"<<endl;
}
else if(b==1)
cout<<"2"<<endl;
else if(b==2)
cout<<"4"<<endl;
else if(b==3)
cout<<"8"<<endl;
}
else if(a==3)
{b=remind;
if(b==0)
{
cout<<"1"<<endl;
}
else if(b==1)
cout<<"3"<<endl;
else if(b==2)
cout<<"9"<<endl;
else if(b==3)
cout<<"7"<<endl;
}
else if(a==7)
{b=remind;
if(b==0)
{
cout<<"1"<<endl;
}
else if(b==1)
cout<<"7"<<endl;
else if(b==2)
cout<<"9"<<endl;
else if(b==3)
cout<<"3"<<endl;
}
else if(a==8)
{b=remind;
if(b==0)
{
cout<<"6"<<endl;
}
else if(b==1)
cout<<"8"<<endl;
else if(b==2)
cout<<"4"<<endl;
else if(b==3)
cout<<"2"<<endl;
}
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন