#P2651. Integer Through Parenthesized Division

    ID: 15917 Type: Default 1000ms 256MiB

Integer Through Parenthesized Division

Integer Through Parenthesized Division

We are given an expression in the form [ a_{1}/a_{2}/a_{3}/\dots/ a_{n} ] where the operations are performed sequentially if no parentheses are added. However, by inserting parentheses we can change the order of operations. For example, the expression [ 1/2/1/4 ] when evaluated normally gives [ \frac{1}{8}, ] but if we insert parentheses as [ (1/2)/(1/4)=2, ] the result is an integer.

Your task is: given the numbers (a_1,a_2,\dots,a_n) (with (n\ge 1)), determine whether it is possible to add parentheses in some way to change the order of operations so that the final result is an integer.

A key observation is that for (n\ge 2) every valid parenthesization leads to an expression of the form [ \frac{a_1 \times \prod_{i\in X}a_i}{a_2 \times \prod_{i\notin X,,i\ge3}a_i} ] for some subset (X) of ({3,4,\ldots,n}). For (n=1) the expression is simply (a_1).

inputFormat

The input begins with an integer (n) ((1 \le n)). The second line contains (n) space-separated positive integers (a_1, a_2, \dots, a_n).

outputFormat

Output a single line containing either "Yes" if it is possible to add parentheses such that the expression evaluates to an integer, or "No" otherwise.

sample

4
1 2 1 4
Yes