Time Limit: 1 Second Memory Limit: 65536 KB
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<iostream>
#include<math.h>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >>T;
int fa=0, kb=1,que[7]={0,1,1,0,1,1,0},i;
while(T--)
{
string a ,b;
cin >>a>>b;
int lena = a.length();
int lenb = b.length();
int last =0,k=0,s=0;
for(int i=0;i<lena;++i)
{
s = a[i]-'0';
k = last*10+s;
last = k%3;
}
s=0,k = 0;
int last1=0;
for(int i=0;i<lenb;++i)
{
s = b[i]-'0';
k = last1*10+s;
last1 = k%3;
}
int sum=0;
if(last1<last)
last1+=3;
for(i=last;i<=last1;i++){
sum+=que[i];
}
cout<<sum%2<<endl;
}
}
错误原因:
1.没注意输入数据的范围,导致w掉了
2.这种类型的题目是属于找规律,很多题目都是一样的。