B. Robin Hood and the Major Oak

time limit per test

1 second

memory limit per test

256 megabytes

In Sherwood, the trees are our shelter, and we are all children of the forest.

The Major Oak in Sherwood is known for its majestic foliage, which provided shelter to Robin Hood and his band of merry men and women.

The Major Oak grows iiii new leaves in the ii-th year. It starts with 11 leaf in year 11.

Leaves last for kk years on the tree. In other words, leaves grown in year ii last between years ii and i+k−1i+k−1 inclusive.

Robin considers even numbers lucky. Help Robin determine whether the Major Oak will have an even number of leaves in year nn.

Input

The first line of the input contains a single integer tt (1≤t≤1041≤t≤104) --- the number of test cases.

Each test case consists of two integers nn, kk (1≤n≤1091≤n≤109, 1≤k≤n1≤k≤n) --- the requested year and the number of years during which the leaves remain.

Output

For each test case, output one line, "YES" if in year nn the Major Oak will have an even number of leaves and "NO" otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Example

Input

Copy

复制代码

5

1 1

2 1

2 2

3 2

4 4

Output

Copy

复制代码
NO
YES
NO
NO
YES

Note

In the first test case, there is only 11 leaf.

In the second test case, k=1k=1, so in the 22-nd year there will be 22=422=4 leaves.

In the third test case, k=2k=2, so in the 22-nd year there will be 1+22=51+22=5 leaves.

In the fourth test case, k=2k=2, so in the 33-rd year there will be 22+33=4+27=3122+33=4+27=31 leaves.

解题说明:此题是一道数学题,每年能生成i^i个树叶,每个树叶能存活k年,求最后的数量是否是偶数。找规律能发现此题为找出以n结尾的连续整数k的和是否为偶数。

cpp 复制代码
#include<iostream>
#include<cmath>
using namespace std;

void solve()
{
	int n, k;
	cin >> n >> k;
	if (n % 2 == 0)
	{
		if (k / 2 % 2 == 0)
		{
			cout << "YES" << '\n';
			return;
		}
		else 
		{
			cout << "NO" << '\n';
			return;
		}
	}
	else
	{
		if ((k / 2 + (k % 2 != 0)) % 2 == 0)
		{
			cout << "YES" << '\n';
			return;
		}
		else
		{
			cout << "NO" << '\n';
			return;
		}
	}
}

int main() 
{
	int t = 1;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}
相关推荐
WWZZ20255 分钟前
快速上手大模型:深度学习2(实践:深度学习基础、线性回归)
人工智能·深度学习·算法·计算机视觉·机器人·大模型·slam
紫荆鱼10 分钟前
设计模式-状态模式(State)
c++·后端·设计模式·状态模式
初级炼丹师(爱说实话版)11 分钟前
算法面经常考题整理(1)机器学习
人工智能·算法·机器学习
深思慎考17 分钟前
微服务即时通讯系统(服务端)——Speech 语音模块开发(2)
linux·c++·微服务·云原生·架构·语音识别·聊天室项目
「QT(C++)开发工程师」25 分钟前
【LUA教程】LUA脚本语言中文教程.PDF
开发语言·pdf·lua
被AI抢饭碗的人1 小时前
算法题(246):负环(bellman_ford算法)
算法
程序定小飞1 小时前
基于springboot的民宿在线预定平台开发与设计
java·开发语言·spring boot·后端·spring
沐怡旸1 小时前
【穿越Effective C++】条款7:为多态基类声明virtual析构函数——C++多态资源管理的基石
c++·面试
天天进步20151 小时前
Python全栈项目--基于计算机视觉的车牌识别系统
开发语言·python·计算机视觉
大数据张老师2 小时前
数据结构——折半查找
数据结构·算法·查找·折半查找