cubic

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Write a function P7:

  • input parameter: integers a, b, c, d satisfying 1max(1\le\max(|a,|,|b,|,|c,|,|d)109|)\le10^9

  • return value: a list of all rational roots of the equation ax3+x^3+bx2+x^2+cx+x+d=0=0, in any order (Each root should be included only once.)

    • Suppose that \[t_0,t_1,,t_n1]\[t\_0,t\_1,\cdots,t\_{n-1}] is the exact answer and \[u_0,u_1,,u_m1]\[u\_0,u\_1,\cdots,u\_{m-1}] is your output.
    • Let r(k)=iZ:0i\<k=0,1,,k1r(k)=\\{i\in\mathbb Z:0\le i\<k\\}=\\{0,1,\cdots,k-1\\} for every non-negative integer kk.
    • Your answer will be graded correct iff there exists a bijective function σ ⁣:r(n)r(m)\sigma\colon r(n)\to r(m) 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 function f(x)=a_nxn+a_n1xn1++a_0f(x)=a\_nx^n+a\_{n-1}x^{n-1}+\cdots+a\_0 with integer coefficients where a_na\_n and a_0a\_0 are nonzero.
    • If f(pq)=0\displaystyle f\left(\frac{p}{q}\right)=0, where p|p| and q|q| are relatively prime positive integers, then a_0p\displaystyle\frac{a\_0}{p} and a_nq\displaystyle\frac{a\_n}{q} are integers.