Division Expression
Time limit1sMemory limit128 MB
Given a left-to-right division expression of n positive integers, decide if some parenthesization yields an integer value, which reduces to checking if x1 times the product of x3..xn is divisible by x2.
- Level
Medium4 of 10
- Topics
- Math, Number theory, Greedy
- Solved
- No attempts yet
Problem
A division expression is an arithmetic expression of the form
where each is a positive integer for . A division expression is evaluated from left to right. For instance, the value of
is .
You may insert parentheses into the expression to change its value. For example, the value of
is .
You are given a division expression . Decide whether it is possible to insert parentheses into to obtain an expression whose value is an integer.
Write a program that, for each data set in a sequence of data sets, reads an expression , determines whether some placement of parentheses makes its value an integer, and reports the result.
Input
The first line contains one positive integer (), the number of data sets. The data sets follow.
The first line of each data set contains an integer (), the number of integers in the expression. Each of the next lines contains exactly one positive integer no greater than ; the -th of these is , the -th integer in the expression.
Output
For each data set, print on its own line YES if the expression can be parenthesized so that its value is an integer, and NO otherwise.