Back
Close

Synthetic division of polynomials

Statement

 Goal

Compute quotient and remainders of polynomials

(3x^4 + 5x^3 + 14x^2 + 9x + 9) / (x + 3) has a quotient of 3x^3 - 4x^2 + 26x - 69 and a remainder of 216 because
3x^4 + 5x^3 + 14x^2 + 9x + 9 = (3x^3 - 4x^2 + 26x - 69) × (x + 3) + 216
If you need help the algorithm is described here https://en.wikipedia.org/wiki/Synthetic_division

Format the output as a space-separated list of coefficients in the quotient, then a comma , and the remainder.
So the example output would be 3.0 -4.0 26.0 -69.0 , 216.0

Note: For results with no remainder keep the size of the original dividend and end with a comma
2.0 1.0 4.0 , 0.0 0.0
Input
Line 1: integer number of terms in Line 3
Line 2: integer number of terms in Line 4
Line 3: the coefficients of the divisor polynomial
Line 4: the coefficients of the dividend polynomial
Output
Line 1 A list of coefficients with a comma separating the remainder with the original length of Line 3
2.0 1.0 4.0 , 0.0 0.0
3.0 -4.0 26.0 -69.0 , 216.0
Constraints
All inputs are integers. Outputs may be terminating decimals, never infinite decimals. Do not round.
Each polynomial will be no more than the 5th degree: x^5 x^4 x^3 x^2 x^1 x^0. Dividend is higher degree than divisor.
Example
Input
2
5
1 3
3 5 14 9 9
Output
3 -4 26 -69 , 216

Game modes
Fastest, Shortest

Test cases
Remainder Test
Input
2 5 1 3 3 5 14 9 9
Output
3 -4 26 -69 , 216

Simple 1 Validator
Input
2 5 2 1 2 5 8 9 4
Output
1 2 3 3 , 1

fixed?? Test
Input
4 5 4 3 2 1 2 5 8 9 4
Output
0.5 0.875 , 4.375 6.75 3.125

Validator 2 Validator
Input
3 6 1 2 1 3 8 8 8 9 4
Output
3 2 1 4 , 0 0

Test 3 Test
Input
3 6 1 2 1 3 8 8 8 9 4
Output
3 2 1 4 , 0 0

Validator 3 Validator
Input
3 6 1 2 1 3 8 8 8 9 4
Output
3 2 1 4 , 0 0

Test 4 Test
Input
3 5 1 0 5 1 2 8 10 19
Output
1 2 3 , 0 4

Validator 4 Validator
Input
3 5 1 0 5 1 2 8 10 19
Output
1 2 3 , 0 4

Solution language

Solution

Stub generator input