Fibonacci in the Pocket

Problem Description
DreamGrid has just found a Fibonacci sequence f1,f2,... and two integers a and b in his right pocket, where fk indicates the k-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 f1=1, f2=1 and fi=fi-1+fi-2 for i>=3 all .

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

The first and only line contains two integers a and b (1<=a<=b<10^10000). Their meanings are described above.

Output
For each test case output one line. If  \sum_{i=a}^bf_iis 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
思路:找规律,每三个数一轮“1 1 0”,“1”代表是奇数“0”代表是偶数。所以取两个数%3的余数来判断这两个数所在位置来判断它的奇偶性。然后另外要解决的点就是大数取余的问题。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int main(){
	char a[10005],b[10005];
	int t;
	scanf("%d", &t);
	while(t--){
		scanf("%s%*c%s%*c",a,b);
		int l1=strlen(a);
		int l2=strlen(b);
		int t1=(a[0]-'0')%3;
		int t2=(b[0]-'0')%3;
		for(int i=1;i<l1;i++){
			t1=(t1*10+a[i]-'0')%3;
		}
		for(int i=1;i<l2;i++){
			t2=(t2*10+b[i]-'0')%3;
		}
		if((t1==t2&&t1!=0)||(t1==0&&t2==1)||(t1==2&&t2==0))
			printf("1\n");
		else
			printf("0\n");
	}
	return 0;
} 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值