#P4752. Divided Prime

    ID: 3606 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>O2优化排序素数判断,质数,筛法洛谷月赛

Divided Prime

Description

Given a number AA, where AA is obtained by multiplying a1,a2,,aNa_1, a_2, \cdots, a_N.

Given a number BB, where BB is obtained by multiplying b1,b2,,bMb_1, b_2, \cdots, b_M.

If AB\frac{A}{B} is a prime number, output YES; otherwise, output NO.

Input Format

Each test point contains multiple test cases. The first line contains an integer TT, which denotes the number of test cases. For each test case:

The first line contains two integers N,MN, M, indicating that AA is obtained by multiplying NN numbers, and BB is obtained by multiplying MM numbers.

The second line contains NN integers, which are the NN numbers that make up AA.

The third line contains MM integers, which are the MM numbers that make up BB.

It is guaranteed that, for any number, the number of times it appears in bi{b_i} is no more than the number of times it appears in ai{a_i}.

Output Format

For each test case:

If AB\frac{A}{B} is a prime number, output YES; otherwise, output NO.

After outputting YES or NO, output a newline character.

2
3 2
5 7 7
5 7
4 2
5 7 7 7
5 7
YES
NO

Hint

For all testdata, 1N1051 \le N \le 10^5, 0MN0 \le M \le N, 1ai,bi10121 \le a_i, b_i \le 10^{12}, 1T101 \le T \le 10, and N105\sum N \le 10^5.

Translated by ChatGPT 5