CF1656H.Equal LCM Subsets

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given two sets of positive integers AA and BB . You have to find two non-empty subsets SAAS_A \subseteq A , SBBS_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 .

输入格式

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

For each test case, there is one line containing two integers n,mn, m ( 1n,m10001 \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 ( 1ai410361 \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 ( 1bi410361 \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 .

输出格式

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| ( 1SAn1 \leq |S_A| \leq n , 1SBm1 \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,,xSAx_1, x_2, \ldots, x_{|S_A|} , the elements of SAS_A , followed by a line with SB|S_B| integers y1,y2,,ySBy_1, y_2, \ldots, y_{|S_B|} , the elements of SBS_B . If there are multiple possible pairs of subsets, you can print any.

输入输出样例

  • 输入#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
首页