Fibonacci in the Pocket

DreamGrid has just found a Fibonacci sequence and two integers and in his right pocket, where indicates the -th element in the Fibonacci sequence.

Please tell DreamGrid if is even or is odd.

Recall that a Fibonacci sequence is an infinite sequence which satisfies , and for all .

Input

There are multiple test cases. The first line of the input contains an integer (about 100), indicating the number of test cases. For each test case:

The first and only line contains two integers and ( ). Their meanings are described above.

Output

For each test case output one line. If is even output "0" (without quotes); If is odd output "1" (without quotes).

Sample Input

6
1 2
1 3
1 4
1 5
123456 12345678987654321
123 20190427201904272019042720190427

Sample Output

0
0
1
0
0
1

Hint

The first few elements of the Fibonacci sequence are: , , , , , ...

思路:写出来斐波那契数列后找到如果这个位置k%3==0||(k+1)%3==0的话,从第一个累加至这个位置就是偶数,否则就是奇数,然后他说是从n到m的和,这很好办,1-m的和减掉从1到n-1的和就OK了,还有一个棘手的是,给的数据很大,有的同学用java 写的其实完全不需要用java 你想啊3的倍数有什么特点==各个位数和加起来也是3的倍数,所以用字符串就行了。

AC代码

#include<iostream>
#include<string>
#include<cstring>
#define ll long long
using namespace std;
int main()
{
	int t;
	scanf("%d",&t);
	for(int i=0;i<t;i++)
	{
		string s1,s2;
		cin>>s1>>s2;
		ll ans1=0;
		ll ans2=0;
		for(int j=0;j<s1.length();j++)
		{
			ans1+=s1[j];
		}
		for(int j=0;j<s2.length();j++)
		{
			ans2+=s2[j];
		}
		ans1-=1;
		bool flag1=false;
		bool flag2=false;
		if(ans1%3==0||(ans1+1)%3==0)
		{
			flag1=true;
		}
		if(ans2%3==0||(ans2+1)%3==0)
		{
			flag2=true;
		} 
		if(flag1&&flag2||(!flag1&&!flag2))
		printf("0\n");
		else
		printf("1\n");
	}
	return 0;
	
}

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值