Polynomial Factoring
https://www.facebook.com/codingcompetitions/hacker-cup/2011/round-1c/problems/B
Last updated
https://www.facebook.com/codingcompetitions/hacker-cup/2011/round-1c/problems/B
Last updated
A polynomial in x of degree D can be written as:
In some cases, a polynomial of degree D can also be written as the product of two polynomials of degrees and , where . For instance,
In this problem, you will be given two polynomials, denoted F and G. Your task is to find a polynomial H such that G * H = F, and each is an integer.
You should first read an integer N, the number of test cases. Each test case will start by describing F and then describe G. Each polynomial will start with its degree D, which will be followed by D+1 integers, denoting . Each polynomial will have a non-zero coefficient for its highest order term.
For each test case, output a single line describing H. If H has degree , you should output a line containing integers, starting with for H. If no H exists such that G*H=F, you should output "no solution".
5
2 6 11 4
1 3 4
2 1 2 1
1 1 1
2 1 0 -1
1 1 1
1 1 1
2 1 2 1
5 1 1 1 1 1 1
3 1 1 1 1
2 1
1 1
1 -1
no solution
no solution