codeforces day 1

A. Coins

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

In Berland, there are two types of coins, having denominations of 22 and kk burles.

Your task is to determine whether it is possible to represent nn burles in coins, i. e. whether there exist non-negative integers xx and yy such that 2⋅x+k⋅y=n2⋅x+k⋅y=n.

Input

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

The only line of each test case contains two integers nn and kk (1≤k≤n≤10181≤k≤n≤1018; k≠2k≠2).

Output

For each test case, print YES if it is possible to represent nn burles in coins; otherwise, print NO. You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).

Example

input

Copy

 

4

5 3

6 1

7 4

8 8

output

Copy

YES
YES
NO
YES

Note

In the first test case, you can take one coin with denomination 22 and one coin with denomination k=3k=3.

In the second test case, you can take three coins with denomination 22. Alternatively, you can take six coins with denomination k=1k=1.

In the third test case, there is no way to represent 77 burles.

In the fourth test case, you can take one coin with denomination k=8k=8.

首先分析题意,其目的就是让你用任意个k金额的硬币和任意个2金额的硬币来表示出n面额的金额。

目的很明确就是通过分析数据来得出什么样的n能用k和2表示出来。

来看数据。

8-8很明显,8是偶数,即一定可以用2面额的硬币来表示,因此我们可以首先将所有为偶数的n面额输出为yes。

if(n%2==0)
printf("yes");

6也是如上的情况,而根据这样的思路我们很容易推出任何k的倍数也一定可以表示出n面额的金额。

if(n%k==0)
printf("yes");

让我们来看看样例中不一样的数据,5-3.

很明显,5-3是由一个三一个二表示出来的。

5-3=2

5-2=3

我们这时候发现n-k得到的数字是2和3这是我们拥有的两枚硬币的大小,因此我们可以想到通过这样也可以排除一大批数字。

这时,我们再想想有没有遗漏。

很明显,没有,因为我们的面额组成是任意个k和任意个2的和,这样的操作下来,我们已经把所有得到n的操作进行完毕了。

完整代码。

#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin >> t;
	while (t--) {
		long long int n, k;
		cin >> n >> k;
		int st = 1;
		if (n % k == 0 || n % 2 == 0)
			st = 0;
		else if ((n - k) % 2 == 0 || (n - 2) % k == 0)
			st = 0;
		if (!st)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值