Braid Squared
Time limit1sMemory limit1024 MB
Given a braid-squared expression and a polynomial, check whether integrating the polynomial twice, with constants C and D, produces that expression.
- Level
Medium4 of 10
- Topics
- Implementation, Math, String
- Solved
- No attempts yet
문제
Daik Manga was doing calculus when the difficulty became unbearable, and a fantasy struck him: what if the integral () were a cute girl with two braids? Using the power of that fantasy, he brought Integral-chan into being.
Daik Manga was delighted by Integral-chan's birth and began to analyze her traits. Integral-chan hugs every expression nearby. The hugged expression is then integrated twice out of joy. Because the expression is integrated once for each braid, the problem calls it a two-braid expression, or a braid-squared expression.
Integral-chan performs indefinite integration, and integrating twice means applying indefinite integration two times. On the first integration, the antiderivative of the given polynomial gets a constant added. On the second integration, a different constant is added.
There is a problem. Integral-chan hugs expressions so often that the original expression can no longer be recovered. The original expressions and the braid-squared expressions are now mixed together, and Integral-chan is depressed with guilt.
Daik Manga does not want to see Integral-chan depressed. So he picks a braid-squared expression and an arbitrary polynomial, and wants to know whether that polynomial is the correct original expression before the braid-squaring. But Daik Manga shouted that he hates math and ran away.
Help Daik Manga comfort Integral-chan. Determine whether each polynomial, when hugged, produces the given braid-squared expression.
입력
The first line contains the number of test cases (). Each test case contains a braid-squared expression and a polynomial chosen by Daik Manga, separated by a space.
Both and are written as ....
Each has the form x^.
- If the degree is , omit x^.
- If the degree is , omit ^.
- If the coefficient is , omit the coefficient.
- If the sign of the first term of or is +, omit the sign.
- In , a term whose coefficient is C has sign +, and its degree is 1.
- In , a term whose coefficient is D has sign +, and its degree is 0.
- A term means the coefficient of the degree- term of the current polynomial is .
The degree is an integer from to .
- The terms of and are given in decreasing order of degree.
- No two terms in the same polynomial have the same degree.
The sign is + or -.
The coefficient is a positive integer, a positive rational number, C, or D.
- In , the coefficient is never C or D.
- In , the coefficient is at most .
- In , every coefficient other than C or D is at most .
- A rational coefficient is written as /.
- In , the numerator is an integer from to .
- In , the numerator is an integer from to .
- The denominator is an integer from to .
- The numerator and denominator are coprime, so the fraction is in lowest terms.
출력
For each test case, print Yes if is the original expression of . Otherwise, print No.
힌트
The integration rule used here is .