#P4752. Prime Quotient Verification

    ID: 17996 Type: Default 1000ms 256MiB

Prime Quotient Verification

Prime Quotient Verification

Given two numbers \(A\) and \(B\) constructed as products of sequences of integers:

\(A = a_1 \times a_2 \times \cdots \times a_N\)

\(B = b_1 \times b_2 \times \cdots \times b_M\)

Determine whether the quotient \(\frac{A}{B}\) is a prime number. Note that if \(\frac{A}{B}\) is not an integer or if it is less than 2, then it is not considered a prime.

inputFormat

The first line contains two integers \(N\) and \(M\) - the number of factors for \(A\) and \(B\) respectively.

The second line contains \(N\) space-separated integers: \(a_1, a_2, \ldots, a_N\).

The third line contains \(M\) space-separated integers: \(b_1, b_2, \ldots, b_M\).

outputFormat

Print YES if \(\frac{A}{B}\) is a prime number; otherwise, print NO.

sample

2 1
3 5
3
YES