Facebook Hacker Cup 2011 Round 1C

Discussion in 'Rebol' started by MaxV, Feb 11, 2011.

  1. MaxV

    MaxV Member

    Polynomial Factoring
    A polynomial in x of degree D can be written as:

    Code:
    a_D x^D + a_D-1 x^(D-1) + ... + a_1 x^1 + a_0
    In some cases, a polynomial of degree D can also be written as the product of two polynomials of degrees D1 and D2, where D = D1 + D2. For instance:

    Code:
    4 x^2 + 11 x^1 + 6 = (4 x + 3) * ( x + 2)
    
    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 a_i is an integer.

    Input
    You should first read an integer N ≤ 60, the number of test cases. Each test case will start by describing F and then describe G. Each polynomial will start with its degree 0 ≤ D ≤ 20, which will be followed by D+1 integers, denoting a_0, a_1, ... , a_D, where -10000 ≤ a_i ≤ 10000. Each polynomial will have a non-zero coefficient for it's highest order term.

    Output
    For each test case, output a single line describing H. If H has degree D_H, you should output a line containing D_H + 1 integers, starting with a_0 for H. If no H exists such that G*H=F, you should output "no solution".

    Example input
    Code:
    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
    
    Example output
    Code:
    2 1
    1 1
    1 -1
    no solution
    no solution
    
    File input:
    http://www.maxvessi.net/rebsite/fhc2011/polynomial_factoring.txt

Share This Page