EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • šŸ‡²šŸ‡¾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🄰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. Meta Coding Competitions
  2. 2011
  3. Round 1C

Polynomial Factoring

https://www.facebook.com/codingcompetitions/hacker-cup/2011/round-1c/problems/B

Question

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

aDxD+aDāˆ’1xDāˆ’1+...+a1x1+a0a_Dx^D + a_{D-1}x^{D-1} + ... + a_1x^1 + a_0aD​xD+aDāˆ’1​xDāˆ’1+...+a1​x1+a0​

In some cases, a polynomial of degree D can also be written as the product of two polynomials of degrees D1D_1D1​ and D2D_2D2​, where D=D1+D2D = D_1 + D_2D=D1​+D2​. For instance,

4x2+11x1+6=(4x1+3)āˆ—(1x1+2)4 x^2 + 11x ^1 + 6 = (4x^1 + 3) * (1 x^1 + 2)4x2+11x1+6=(4x1+3)āˆ—(1x1+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 aia_iai​ is an integer.

Input Format

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 a0,a1,...,aDa_0, a_1, ... , a_Da0​,a1​,...,aD​. Each polynomial will have a non-zero coefficient for its highest order term.

Constraints

N≤60N \le 60N≤60
0≤D≤200 ≤ D ≤ 200≤D≤20
āˆ’10000≤ai≤10000-10000 ≤ a_i ≤ 10000āˆ’10000≤ai​≤10000

Output Format

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

Sample Inputs:

Input

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

Output

2 1
1 1
1 -1
no solution
no solution

Solution

PreviousN-FactorfulNextRisky Slide

Last updated 2 months ago