CF1719B.Mathematical Circus

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A new entertainment has appeared in Buryatia — a mathematical circus! The magician shows two numbers to the audience — nn and kk, where nn is even. Next, he takes all the integers from 11 to nn, and splits them all into pairs (a,b)(a, b) (each integer must be in exactly one pair) so that for each pair the integer (a+k)⋅b(a + k) \cdot b is divisible by 44 (note that the order of the numbers in the pair matters), or reports that, unfortunately for viewers, such a split is impossible.

Burenka really likes such performances, so she asked her friend Tonya to be a magician, and also gave him the numbers nn and kk.

Tonya is a wolf, and as you know, wolves do not perform in the circus, even in a mathematical one. Therefore, he asks you to help him. Let him know if a suitable splitting into pairs is possible, and if possible, then tell it.

布里亚特地区出现了一种新型娱乐活动——数学马戏团!魔术师向观众展示两个数:nn 和 kk,其中 nn 为偶数。接着,他取出从 11 到 nn 的所有整数,并将它们全部两两配对成形如 (a,b)(a, b) 的有序对(每个整数必须且仅能出现在一个有序对中),使得对每个有序对,整数 (a+k)⋅b(a + k) \cdot b 都能被 44 整除(注意:有序对中数字的顺序是重要的);若这样的配对方式不存在,则魔术师会遗憾地告知观众该配对不可行。

布伦卡非常喜爱这类表演,于是她请朋友托尼娅担任魔术师,并把数字 nn 和 kk 告诉了他。

托尼娅是一只狼,而众所周知,狼绝不会在马戏团中表演——哪怕是在数学马戏团中也不例外。因此,他请你来帮忙:请告诉他是否存在满足条件的配对方案;若存在,请给出一种具体方案。

输入格式

The first line contains one integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. The following is a description of the input data sets.

The single line of each test case contains two integers nn and kk (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5, 0≤k≤1090 \leq k \leq 10^9, nn is even) — the number of integers and the number being added kk.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 表示测试用例的数量。接下来是对各组输入数据的描述。

每个测试用例仅有一行,包含两个整数 nn 和 kk(2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5,0≤k≤1090 \leq k \leq 10^9,且 nn 为偶数)—— 分别表示整数的个数以及被加数 kk。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, first output the string "YES" if there is a split into pairs, and "NO" if there is none.

If there is a split, then in the following n2\frac{n}{2} lines output pairs of the split, in each line print 22 numbers — first the integer aa, then the integer bb.

对于每个测试用例,如果存在一种配对划分方式,则首先输出字符串 "YES";否则输出 "NO"。

如果存在配对划分,则在接下来的 n2\frac{n}{2} 行中输出该划分的各对数,每行输出 22 个整数 —— 先输出整数 aa,再输出整数 bb。

输入输出样例

  • 输入#1

    4
    4 1
    2 0
    12 10
    14 11

    输出#1

    YES
    1 2
    3 4
    NO
    YES
    3 4
    7 8
    11 12
    2 1
    6 5
    10 9
    YES
    1 2
    3 4
    5 6
    7 8
    9 10
    11 12
    13 14

说明/提示

In the first test case, splitting into pairs (1,2)(1, 2) and (3,4)(3, 4) is suitable, same as splitting into (1,4)(1, 4) and (3,2)(3, 2).

In the second test case, (1+0)⋅2=1⋅(2+0)=2(1 + 0) \cdot 2 = 1 \cdot (2 + 0) = 2 is not divisible by 44, so there is no partition.

在第一个测试用例中,划分为 (1,2)(1, 2) 和 (3,4)(3, 4) 是可行的,划分为 (1,4)(1, 4) 和 (3,2)(3, 2) 同样可行。

在第二个测试用例中,(1+0)⋅2=1⋅(2+0)=2(1 + 0) \cdot 2 = 1 \cdot (2 + 0) = 2 不能被 44 整除,因此不存在满足条件的划分。

输入解题思路,AI测评打分。不知道怎么写?

首页