#x1020. cf1656H Equal LCM Subsets

cf1656H Equal LCM Subsets

Equal LCM Subsets

题面翻译

有两个集合A,BA,B,大小分别为n,mn,m,你需要找两个非空子集SAA,SBBS_A\subseteq A,S_B\subseteq B,使得SAS_A中的元素的最小公倍数和SBS_B中的元素的最小公倍数相等。若无解,输出NO,有解输出YES和任意一组解。

多组数据,数据组数$t\leq200,1\leq \sum n,\sum m\leq1000,1\leq a_i,b_i\leq4\times10^{36}$。

题目描述

You are given two sets of positive integers A A and B B . You have to find two non-empty subsets SAA S_A \subseteq A , SBB S_B \subseteq B so that the least common multiple (LCM) of the elements of SA S_A is equal to the least common multiple (LCM) of the elements of SB S_B .

输入格式

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

For each test case, there is one line containing two integers n,m n, m ( 1n,m1000 1 \leq n, m \leq 1000 ), the sizes of the sets A A and B B , respectively.

The next line contains n n distinct integers a1,a2,,an a_1, a_2, \ldots, a_n ( 1ai41036 1 \leq a_i \leq 4 \cdot 10^{36} ), the elements of A A .

The next line contains m m distinct integers b1,b2,,bm b_1, b_2, \ldots, b_m ( 1bi41036 1 \leq b_i \leq 4 \cdot 10^{36} ), the elements of B B .

The sum of n n for all test cases and the sum of m m for all test cases is at most 1000 1000 .

输出格式

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| ( 1SAn 1 \leq |S_A| \leq n , 1SBm 1 \leq |S_B| \leq m ), the sizes of the subsets SA S_A and SB S_B

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

样例 #1

样例输入 #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

请到CF官网提交