CF1656H.Equal LCM Subsets

NOI/NOI+/CTSC

通过率:0%

时间限制:10.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given two sets of positive integers AA and BB. You have to find two non-empty subsets SA⊆AS_A \subseteq A, SB⊆BS_B \subseteq B so that the least common multiple (LCM) of the elements of SAS_A is equal to the least common multiple (LCM) of the elements of SBS_B.

给你两组正整数 AA 和 BB。你需要找出两个非空子集 SA⊆AS_A \subseteq A、SB⊆BS_B \subseteq B,使得 SAS_A 中所有元素的最小公倍数(LCM)等于 SBS_B 中所有元素的最小公倍数(LCM)。

输入格式

The input consists of multiple test cases. The first line of the input contains one integer tt (1≤t≤2001 \leq t \leq 200), the number of test cases.

For each test case, there is one line containing two integers n,mn, m (1≤n,m≤10001 \leq n, m \leq 1000), the sizes of the sets AA and BB, respectively.

The next line contains nn distinct integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤4⋅10361 \leq a_i \leq 4 \cdot 10^{36}), the elements of AA.

The next line contains mm distinct integers b1,b2,…,bmb_1, b_2, \ldots, b_m (1≤bi≤4⋅10361 \leq b_i \leq 4 \cdot 10^{36}), the elements of BB.

The sum of nn for all test cases and the sum of mm for all test cases is at most 10001000.

输入包含多个测试用例。输入的第一行包含一个整数 tt(1≤t≤2001 \leq t \leq 200),表示测试用例的数量。

对于每个测试用例,有一行包含两个整数 n,mn, m(1≤n,m≤10001 \leq n, m \leq 1000),分别表示集合 AA 和 BB 的大小。

下一行包含 nn 个互不相同的整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤4⋅10361 \leq a_i \leq 4 \cdot 10^{36}),即集合 AA 的元素。

再下一行包含 mm 个互不相同的整数 b1,b2,…,bmb_1, b_2, \ldots, b_m(1≤bi≤4⋅10361 \leq b_i \leq 4 \cdot 10^{36}),即集合 BB 的元素。

所有测试用例中 nn 的总和与所有测试用例中 mm 的总和均不超过 10001000。

输出格式

For each test case, if there do not exist two subsets with equal least common multiple, output one line with NO.

Otherwise, output one line with YES, followed by a line with two integers ∣SA∣,∣SB∣|S_A|, |S_B| (1≤∣SA∣≤n1 \leq |S_A| \leq n, 1≤∣SB∣≤m1 \leq |S_B| \leq m), the sizes of the subsets SAS_A and SBS_B

The next line should contain ∣SA∣|S_A| integers x1,x2,…,x∣SA∣x_1, x_2, \ldots, x_{|S_A|}, the elements of SAS_A, followed by a line with ∣SB∣|S_B| integers y1,y2,…,y∣SB∣y_1, y_2, \ldots, y_{|S_B|}, the elements of SBS_B. If there are multiple possible pairs of subsets, you can print any.

对于每个测试用例,若不存在两个具有相等最小公倍数(LCM)的子集,则输出一行 NO。

否则,输出一行 YES,随后输出一行包含两个整数 ∣SA∣,∣SB∣|S_A|, |S_B|(1≤∣SA∣≤n1 \leq |S_A| \leq n, 1≤∣SB∣≤m1 \leq |S_B| \leq m),分别表示子集 SAS_A 和 SBS_B 的大小。

接下来的一行应包含 ∣SA∣|S_A| 个整数 x1,x2,…,x∣SA∣x_1, x_2, \ldots, x_{|S_A|},即 SAS_A 的元素;再下一行包含 ∣SB∣|S_B| 个整数 y1,y2,…,y∣SB∣y_1, y_2, \ldots, y_{|S_B|},即 SBS_B 的元素。若存在多组可能的子集对,输出任意一组即可。

输入输出样例

  • 输入#1

    4
    3 4
    5 6 7
    2 8 9 10
    4 4
    5 6 7 8
    2 3 4 9
    1 3
    1
    1 2 3
    5 6
    3 4 9 7 8
    2 15 11 14 20 12

    输出#1

    NO
    YES
    1 2
    6
    2 3
    YES
    1 1
    1
    1
    YES
    3 2
    3 7 4
    12 14

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

首页