Common Roots

Time Limit: 2000ms
Memory Limit: 65536KB
This problem will be judged on HDU. Original ID: 3892
64-bit integer IO format: %I64d      Java class name: Main

Description

We have many polynomials modulo p (p is a prime number). An interesting issue would be to determine whether they have some roots in common. Notice roots we mention here are integers in modulo p system (0 <= root < p). Moreover, if the given polynomial is of order r, we will guarantee that it has r roots.
For example, we have
x^2 + 13x + 36 (mod 37)
x^3 + 14x^2 + 49x + 36 (mod 37)
If x = 33 or x = 28, both of them would give the value of 0. So 33 and 28 are the roots in common.

Input

There are many test cases (less than1000).
In each case, the integer in the first line is n (the number of polynomials in this case). Then n lines followed. Each of them starts with an integer r (order of polynomials, r <= 50), and r + 1 integers (a(r), a(r-1) ,..., a(0)), which means the polynomial goes like:
a(r) * x^r + a(r-1) * x^(r-1) + … +a(1) * x + a(0) (mod 999983).
To make it easier, p is set to be 999983, as you see.

Output

For each case, just output “YES” if they have common roots, otherwise “NO” in a single line.

Sample Input

2
2 1 13 36
3 1 14 49 36

Sample Output

YES

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .