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 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
思路:找规律,每三个数一轮“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;
}