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代码
|
Fibonacci in the Pocket
最新推荐文章于 2020-08-17 12:31:37 发布