QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 256 MB 总分: 100

#11018. 口罩分配

统计

如今,Dreamgrid 王国正遭受着一场全国性的流行病。幸运的是,Baobao 总统正与疾病控制中心(CDC)高效合作,尽其所能控制局势。

Baobao 总统从他的亿万富翁朋友 Reku 那里收到了 $n \times m$ 个医用口罩。作为 CDC 的负责人,你需要妥善分配这些口罩。Dreamgrid 王国有两种医院:$n$ 所收治重症患者的高级医院,以及 $m$ 所收治轻症患者的方舱医院。

在分配给医院之前,你必须将口罩装入盒中。请注意,为了防止污染,盒子不得拆封,且你只知道这些盒子要么会被分配给高级医院,要么会被分配给方舱医院。也就是说,必须存在一种将口罩盒分为 $m$ 组(每组 $n$ 个口罩)的方法,以及一种将口罩盒分为 $n$ 组(每组 $m$ 个口罩)的方法。

你希望盒子数量最少,并请提供一个口罩数量的字典序最大的序列。如果两个长度相同的序列 $a$ 和 $b$,存在一个整数 $i$ 使得:

  • 对于所有 $j < i$,都有 $a_j = b_j$;且
  • $a_i > b_i$

则称序列 $a$ 的字典序大于序列 $b$。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$ ($1 \le T \le 100$),表示测试数据的组数。

对于每组测试数据,唯一的一行包含两个整数 $n, m$ ($1 \le n, m \le 10^4$),分别表示高级医院和方舱医院的数量。

输出格式

对于每组测试数据,请输出两行。第一行包含一个整数 $k$,表示最少的盒子数量。第二行输出 $k$ 个整数,表示字典序最大的序列。

样例

输入 1

2
5 4
3 3

输出 1

8
4 4 4 4 1 1 1 1
3
3 3 3

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.