
ZOJ Problem Set  2896
Given two polynomials with integer coefficients, check if they have a common factor. A common factor is a polynomial with degree larger than 0 that will divide evenly into both polynomials. Input There are many test cases. Every test case begins with a line containing two integers n and m, 0<= n, m <= 100. The second line contains n+1 integers An(An != 0), An1, An2, ... A1, A0. Ai is the coefficient of the term with degree i in the first polynomial. The third line contains m+1 integers Bm(Bm != 0), Bm1, Bm2, ... B1, B0. Bi is the coefficient of the term with degree i in the second polynomial. All coefficients are between 4000 and 4000 inclusive. Output For each test case, print "YES" if the two polynomials have a common factor in a line, or print "NO" instead if the two polynomials have no common factor. Sample Input
2 2 Sample Output
NO Author: HE, Rongqiang Source: ZOJ Monthly, January 2008 