Prime Factorization
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Zenyk is solving the following problem in his math class — he is given a set of prime numbers \(p_1, p_2, ..., p_k\) and a target number \(n\). His task is to determine whether \(n\) can be factored into primes using only the given prime numbers? Formally, you need to tell whether there exists a set of non-negative integers \(e_1, e_2, ..., e_k\) such that \(p_1^{e_1} \cdot p_2^{e_2} \cdot ... \cdot p_k^{e_k} = n\).
Input
The first line contains two numbers \(n\) and \(k\). The second line contains \(k\) prime numbers \(p_i\) separated by a space.
Output
Output YES if such a factorization is possible,
otherwise output NO.
Constraints
\(2 \leq n \leq 10^9\),
\(1 \leq k \leq 100\),
\(1 \leq p_i \leq 10^9\),
\(p_i\) is prime.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 12 3 2 3 7 | YES |
| Input (stdin) | Output (stdout) |
|---|---|
| 15 5 7 11 13 3 11 | NO |
Notes
In the first test, \(2^2 \cdot 3^1 \cdot 7^0 = 12\).
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|