CF1656H.Equal LCM Subsets
NOI/NOI+/CTSC
通过率:0%
时间限制:10.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two sets of positive integers A and B. You have to find two non-empty subsets SA⊆A, SB⊆B so that the least common multiple (LCM) of the elements of SA is equal to the least common multiple (LCM) of the elements of SB.
给你两组正整数 A 和 B。你需要找出两个非空子集 SA⊆A、SB⊆B,使得 SA 中所有元素的最小公倍数(LCM)等于 SB 中所有元素的最小公倍数(LCM)。
输入格式
The input consists of multiple test cases. The first line of the input contains one integer t (1≤t≤200), the number of test cases.
For each test case, there is one line containing two integers n,m (1≤n,m≤1000), the sizes of the sets A and B, respectively.
The next line contains n distinct integers a1,a2,…,an (1≤ai≤4⋅1036), the elements of A.
The next line contains m distinct integers b1,b2,…,bm (1≤bi≤4⋅1036), the elements of B.
The sum of n for all test cases and the sum of m for all test cases is at most 1000.
输入包含多个测试用例。输入的第一行包含一个整数 t(1≤t≤200),表示测试用例的数量。
对于每个测试用例,有一行包含两个整数 n,m(1≤n,m≤1000),分别表示集合 A 和 B 的大小。
下一行包含 n 个互不相同的整数 a1,a2,…,an(1≤ai≤4⋅1036),即集合 A 的元素。
再下一行包含 m 个互不相同的整数 b1,b2,…,bm(1≤bi≤4⋅1036),即集合 B 的元素。
所有测试用例中 n 的总和与所有测试用例中 m 的总和均不超过 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∣ (1≤∣SA∣≤n, 1≤∣SB∣≤m), the sizes of the subsets SA and SB
The next line should contain ∣SA∣ integers x1,x2,…,x∣SA∣, the elements of SA, followed by a line with ∣SB∣ integers y1,y2,…,y∣SB∣, the elements of SB. If there are multiple possible pairs of subsets, you can print any.
对于每个测试用例,若不存在两个具有相等最小公倍数(LCM)的子集,则输出一行 NO。
否则,输出一行 YES,随后输出一行包含两个整数 ∣SA∣,∣SB∣(1≤∣SA∣≤n, 1≤∣SB∣≤m),分别表示子集 SA 和 SB 的大小。
接下来的一行应包含 ∣SA∣ 个整数 x1,x2,…,x∣SA∣,即 SA 的元素;再下一行包含 ∣SB∣ 个整数 y1,y2,…,y∣SB∣,即 SB 的元素。若存在多组可能的子集对,输出任意一组即可。
输入输出样例
输入#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测评打分。不知道怎么写?