题目链接:https://www.acwing.com/problem/content/4414/
题目如下:
/*
结论:2*(10^9) 常使用两种解决办法 1、快速幂+矩阵乘 2、循环
本题的初始状态为0 1 2,经过每轮操作得到的结果如下
第一轮 1 0 2
第二轮 1 2 0
第三轮 2 1 0
第四轮 2 0 1
第五轮 0 2 1
第六轮 0 1 2
第七轮 。。。,此时开始循环,则得到本题的循环周期为6,则每次只需要对6取模即可
*/
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
int n,x;
cin>>n>>x;
string state="012";
n=n%6;
for(int i=1;i<=n;i++){
if(i%2==1) swap(state[0],state[1]);
else swap(state[1],state[2]);
}
cout<<state[x]<<endl;
return 0;
}