#C3315. Pair Product Existence
Pair Product Existence
Pair Product Existence
Given an array of n integers and an integer p, determine whether there exists a pair of distinct elements in the array such that their product is equal to p.
Formally, find two different indices i and j (with i ≠ j) such that
\(a_i \times a_j = p\)
If such a pair exists, print "YES"; otherwise, print "NO".
Note that the array may contain zero and negative numbers. In case p is zero, finding a pair where one of the numbers is zero is valid provided that there are at least two occurrences or the other number multiplied by a non-zero number yields zero.
inputFormat
The first line contains two space-separated integers n
and p
, where n
is the number of elements in the array and p
is the target product.
The second line contains n
space-separated integers representing the array elements.
Example:
5 16 2 4 6 8 10
outputFormat
Output a single line containing either YES
if there exists a pair of distinct elements whose product equals p
or NO
otherwise.
5 16
2 4 6 8 10
YES