#x1020. cf1656H Equal LCM Subsets
cf1656H Equal LCM Subsets
Equal LCM Subsets
题面翻译
有两个集合,大小分别为,你需要找两个非空子集,使得中的元素的最小公倍数和中的元素的最小公倍数相等。若无解,输出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 and . You have to find two non-empty subsets , so that the least common multiple (LCM) of the elements of is equal to the least common multiple (LCM) of the elements of .
输入格式
The input consists of multiple test cases. The first line of the input contains one integer ( ), the number of test cases.
For each test case, there is one line containing two integers ( ), the sizes of the sets and , respectively.
The next line contains distinct integers ( ), the elements of .
The next line contains distinct integers ( ), the elements of .
The sum of for all test cases and the sum of for all test cases is at most .
输出格式
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 ( , ), the sizes of the subsets and
The next line should contain integers , the elements of , followed by a line with integers , the elements of . 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官网提交