#P1520. 因式分解
因式分解
Description
Factor the polynomial over the ring of integer polynomials (in short, this is a factorization problem), and continue factoring until all factors are irreducible polynomials (i.e., no factor can be further factored).
Input Format
A single line containing a positive integer .
Output Format
Output one line with a single string representing the factorization result.
In the final output, each factor should contain no spaces. Whenever , , the multiplication sign, and parentheses can be omitted, do so whenever possible.
If there are multiple factors, each factor should be written in descending powers, and its leading coefficient must be positive.
In addition, order the factors as follows:
- Prefer factors of lower degree. For factors with the same degree, compare their coefficients term by term from higher to lower exponents (including omitted terms whose coefficients are ).
- For coefficients, compare absolute values first, then signs. A smaller absolute value is lexicographically smaller; if absolute values are equal, a negative sign is lexicographically smaller than a positive sign. Factors with lexicographically smaller sequences should be output earlier. See the sample.
12
(x-1)(x+1)(x^2+1)(x^2-x+1)(x^2+x+1)(x^4-x^2+1)
Hint
Hint
Constraints and Conventions
- For of the testdata, .
- For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号