#P4506. [CTSC2013] 因式分解

[CTSC2013] 因式分解

Description

By the Fundamental Theorem of Algebra, counting multiplicity, a degree nn polynomial over the complex numbers has exactly nn zeros (points where the function value is 00). You are given an integer-coefficient polynomial F[x]F[x] whose nn zeros are all rational numbers (i.e., can be written as a ratio of two integers). If we deduplicate all nonzero zeros (the variable is not 00 while the function value is 00), we obtain rr distinct nonzero zeros, where the ii-th nonzero zero can be written as:

sgni×qipisgn_i \times \frac{q_i}{p_i}

Here sgnisgn_i denotes the sign of the ii-th zero, and pip_i and qiq_i are two coprime positive integers.

You are given F[x]F[x]. Output its factorized form.

Input Format

The input contains exactly one line: the polynomial F[x]F[x].

The polynomial is always given in the following form: anxn+an1xn1++a1x+a0 a_n x^n + a_{n-1} x^{n-1} + \cdots + a_1 x + a_0

The terms are in descending degree. Each aia_i is an integer. If ai=0a_i = 0, that term is omitted. If aia_i is negative, the preceding plus sign is omitted. If ai=1|a_i| = 1 and i0i \ne 0, the 11 is not printed. It is guaranteed that an0a_n \ne 0. See the sample input.

Output Format

Output one line: the factorized form in the following format: $a_n (x + u_1 / v_1)^{t_1} (x + u_2 / v_2)^{t_2} \cdots (x + u_s / v_s)^{t_s}$

Here uu and vv are coprime, and vv is a positive integer.

ui/viu_i / v_i are sorted from largest to smallest. If ui/vi=0u_i / v_i = 0, that factor is xtix^{t_i}. If ui/viu_i / v_i is negative, the plus sign is omitted. If vi=1v_i = 1, then /vi/ v_i is omitted.

If ti=1t_i = 1, the exponent is omitted.

If an=±1a_n = \pm 1, the 11 is omitted. See the sample output.

8x^7-258x^5+2112x^3-512x
8(x-4)^2(x-1/2)x(x+1/2)(x+4)^2
-x^2+2x-1
-(x-1)^2

Hint

测试点编号 多项式最高次数 互异零点数 系数范围(绝对值)
11 22 10\le 10
22 44 100\le 100
33 77 106\le 10^6
44 1010 107\le 10^7
55 1212 1016\le 10^{16}
66 3535 55 1024\le 10^{24}
77 3939 1068\le 10^{68}
88 4646 44 10104\le 10^{104}
99 8080 22 1012\le 10^{12}
1010 5050 11 10316\le 10^{316}

pi,qip_i, q_i satisfy:

$$\prod_{i=1}^r p_i \le 10^6, \prod_{i=1}^r q_i \le 10^6.$$

Translated by ChatGPT 5