【Codeforces】1208A. XORinacci

题目描述

Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows:

  • f(0)=af(0)=a;
  • f(1)=bf(1)=b;
  • f(n)=f(n−1)⊕f(n−2)f(n)=f(n−1)⊕f(n−2) when n>1n>1, where ⊕⊕ denotes the bitwise XOR operation.

You are given three integers aa, bb, and nn, calculate f(n)f(n).

You have to answer for TT independent test cases.

Input

The input contains one or more independent test cases.

The first line of input contains a single integer TT (1≤T≤1031≤T≤103), the number of test cases.

Each of the TT following lines contains three space-separated integers aa, bb, and nn (0≤a,b,n≤1090≤a,b,n≤109) respectively.

Output

For each test case, output f(n)f(n).

Example

input
3
3 4 2
4 5 0
325 265 1231232
output
7
4
76

Note

In the first example, f(2)=f(0)⊕f(1)=3⊕4=7f(2)=f(0)⊕f(1)=3⊕4=7.

题解

打表找规律即可。

代码

#include<iostream>
using namespace std;

int a,b,n;

int main()
{
    int T;
    cin>>T;
    while(T--){
        cin>>a>>b>>n;
        int ans=0;
        switch(n%3){
            case 0:ans=a;break;
            case 1:ans=b;break;
            case 2:ans=a^b;break;
        }
        cout<<ans<<endl;
    }
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值