cubic
Time limit1sMemory limit512 MB
Given integer coefficients of a cubic, return every rational root, using the rational root theorem to test candidate divisors of the constant and leading terms.
- Level
Medium5 of 10
- Topics
- Math, Number theory, Brute force, Implementation
- Solved
- No attempts yet
Problem
Write a function P7:
-
Input parameters: integers
a,b,c,dsatisfyingabcd -
Return value: a list of all rational roots of the equation
abcd, in any order. (Each root should be included only once.)- Suppose the exact answer is and your output is .
- For every non-negative integer , let .
- Your answer is graded correct if and only if there exists a bijective function such that [\frac{|u_{\sigma(i)}-t_i|}{\max(1,|t_i|)}\le10^{-6}\qquad\text{for all }i\in r(n)]
-
Hint: The rational root theorem states the following.
- Consider a polynomial with integer coefficients where and are nonzero.
- If , where and are relatively prime positive integers, then and are integers.