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: , , , , , ...
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn=10050;
char ch[]="aeiouy";
char a[maxn],b[maxn];
void solve(){
int T;
scanf("%d",&T);
while(T--){
scanf("%s %s",a,b);
int len_a=strlen(a),len_b=strlen(b);
int num_a=0,num_b=0,flag1=0,flag2=0;
for(int i=0;i<len_a;i++){
num_a=(num_a+a[i]-'0')%3;
}
for(int i=0;i<len_b;i++){
num_b=(num_b+b[i]-'0')%3;
}
num_a=((num_a-1)%3+3)%3;
if(num_a==1) flag1=1;
if(num_b==1) flag2=1;
printf("%d\n",(flag1+flag2)%2);
}
}
int main(){
solve();
return 0;
}