QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#10833. 二分图上的 GCD

統計

给定一个完全二分图,左侧有 $n$ 个节点,右侧有 $m$ 个节点,其中左侧的任意节点都与右侧的所有节点相连。你的任务是为这些节点分配数值,使得每个整数 $i \in [1, n + m]$ 恰好出现一次,并且对于任意环,环上所有节点数值的最大公约数(GCD)等于 1。

一组正整数的最大公约数是能整除所有这些整数的最大整数。例如,$\text{GCD}(4, 6) = 2$,$\text{GCD}(6, 9, 15) = 3$。

输入格式

第一行包含一个整数 $T(1 \le T \le 100)$,表示测试用例的数量。

每个测试用例包含一行,包含两个整数 $n, m(1 \le n, m \le 10^5)$。保证 $\sum \max(n, m) \le 2 \cdot 10^5$。

输出格式

对于每个测试用例,如果存在一种可能的分配方案,输出 YES。然后输出两行,第一行表示左侧节点的数值,第二行表示右侧节点的数值。如果存在多种答案,输出任意一种即可。每行的整数用空格分隔,且不要在每行末尾打印多余的空格。如果打印的元素数量错误,可能会得到 Presentation Error 的判决。

如果不存在可能的分配方案,输出 NO

样例

样例输入 1

2
3 4
9 9

样例输出 1

YES
1 4 7
6 2 5 3
NO

说明

下图展示了一个 $n = 3, m = 4$ 的正确图示。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.