Day 1: Lens Stacking

easyGreedytwo pointersBinary Search
An optical technician has a collection of lenses, each with an integer magnification factor. The magnification factors of the lenses are given in a sorted array LL of length NN.

By stacking two distinct lenses together, their magnifications multiply. That is, using lens ii and lens jj (ii not equal to jj), the total magnification becomes Li×LjL_i \times L_j.

You are given a target magnification MM. Determine whether there exists any pair of distinct lenses whose combined magnification is exactly MM.

Input Format:

The first line contains two integers NN and MM (2N21052 \le N \le 2 \cdot 10^5, 1M10121 \le M \le 10^{12}) --- the number of lenses and the target magnification.
The second line contains NN integers L1,L2,,LNL_1, L_2, \ldots, L_N (1Li1061 \le L_i \le 10^6), representing the magnification factors of the lenses. The array is sorted in non-decreasing order.

Output Format:

Output YES if there exists a pair of lenses with magnifications that multiply to MM. Otherwise, output NO.

Examples:

Example 1:

Input:

2 50
5 10

Output:

YES

Example 2:

Input:

4 5000000
10 100 2000 500000

Output:

YES

Example 3:

Input:

2 90
1 2

Output:

NO

Code

Loading Editor...