Editorial for RGPC '17 P3 - Intercept
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
The conceptually simplest method of expanding using the distributive property will be described here. Firstly, we can store the coefficients of the terms in arrays. Save the first factor in an array  (factors of polynomial functions take the form 
, and in this case, the coefficient of 
 will always be 
), and then iterate through the factors.
For each factor, call the function , where 
 is the previous result of expansion (or the first array), and 
 is the new array 
. In this function, we will use a nested for loop, where the outer loop iterates through 
 and the inner loop iterates through 
. In each iteration, multiply 
 by 
, and then add that value to a third array 
 (the resulting expression) at the position 
. Note that the length of 
 should be greater than 
 and 
, depending on their degrees.
Lastly, to determine the leading coefficient, substitute the values of the known point into the function. The recommended way of doing this would be to substitute the known  value as you loop through the terms, then dividing the known 
 value by the result, because substituting into standard form and using 
pow() may result in floating-point inaccuracies. Remember to multiply all coefficients by the leading coefficient before outputting.
Time complexity: 
Comments