A15324 | Mathematical Circus
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A new entertainment has appeared in Buryatia — a mathematical circus! The magician shows two numbers to the audience — $n$ and $k$ , where $n$ is even. Next, he takes all the integers from $1$ to $n$ , and splits them all into pairs $(a, b)$ (each integer must be in exactly one pair) so that for each pair the integer $(a + k) \cdot b$ is divisible by $4$ (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 $n$ and $k$ .
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.
Burenka really likes such performances, so she asked her friend Tonya to be a magician, and also gave him the numbers $n$ and $k$ .
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.
输入格式
The first line contains one integer $t$ ( $1 \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 $n$ and $k$ ( $2 \leq n \leq 2 \cdot 10^5$ , $0 \leq k \leq 10^9$ , $n$ is even) — the number of integers and the number being added $k$ .
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ .
The single line of each test case contains two integers $n$ and $k$ ( $2 \leq n \leq 2 \cdot 10^5$ , $0 \leq k \leq 10^9$ , $n$ is even) — the number of integers and the number being added $k$ .
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \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 $\frac{n}{2}$ lines output pairs of the split, in each line print $2$ numbers — first the integer $a$ , then the integer $b$ .
If there is a split, then in the following $\frac{n}{2}$ lines output pairs of the split, in each line print $2$ numbers — first the integer $a$ , then the integer $b$ .
输入输出样例
输入 #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)$ and $(3, 4)$ is suitable, same as splitting into $(1, 4)$ and $(3, 2)$ .
In the second test case, $(1 + 0) \cdot 2 = 1 \cdot (2 + 0) = 2$ is not divisible by $4$ , so there is no partition.
In the second test case, $(1 + 0) \cdot 2 = 1 \cdot (2 + 0) = 2$ is not divisible by $4$ , so there is no partition.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted