A. Sum of Odd Integers

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two integers nn and kk. Your task is to find if nn can be represented as a sum of kk distinct positive odd (not divisible by 22) integers or not.

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1≤t≤1051≤t≤105) — the number of test cases.

The next tt lines describe test cases. The only line of the test case contains two integers nn and kk (1≤n,k≤1071≤n,k≤107).

Output

For each test case, print the answer — "YES" (without quotes) if nn can be represented as a sum of kk distinct positive odd (not divisible by 22) integers and "NO" otherwise.

Example

input

Copy

6
3 1
4 2
10 3
10 2
16 4
16 5

output

Copy

YES
YES
NO
YES
YES
NO

Note

In the first test case, you can represent 33 as 33.

In the second test case, the only way to represent 44 is 1+31+3.

In the third test case, you cannot represent 1010 as the sum of three distinct positive odd integers.

In the fourth test case, you can represent 1010 as 3+73+7, for example.

In the fifth test case, you can represent 1616 as 1+3+5+71+3+5+7.

In the sixth test case, you cannot represent 1616 as the sum of five distinct positive odd integers.

解题说明:此题是一道数学题,由题意知道首先必须 n,k奇偶相同,然后就是 k 个奇数相加最小值大于 n肯定不能组成,他们的和由等差公式求得为 k+k∗(k-1)

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	int t, i, j;
	unsigned long long n, k;
	scanf("%d", &t);
	for (i = 1; i <= t; i++)
	{
		scanf("%llu%llu", &n, &k);
		if (((n % 2 == 0 && k % 2 == 0) || (n % 2 == 1 && k % 2 == 1)) && n >= k * k)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}
发布了1769 篇原创文章 · 获赞 388 · 访问量 279万+

猜你喜欢

转载自blog.csdn.net/jj12345jj198999/article/details/105151351