P28241 [洛谷] Factorization II
普及+
题目描述

Problem Description

Xiao Yu has started middle school and is learning factorization. However, she can't solve it no matter what. So she asks for your help.

She shows you her homework, which is about factorization. Since she is just beginning to learn, the difficulty has been reduced.

We assume that the algebra in the homework only involves one variable \( x \). The highest exponent is 2, and the coefficient of the highest exponent is 1. When the coefficient in front of \( x \) is 1, the 1 is omitted... (anyway, the homework questions follow our usual writing style).

Let's help her solve this "simple" problem! Although it sounds quite easy, programming requires considering many situations!

It is guaranteed that the numbers in the homework answers are all integers.

Input Format

A polynomial, as described earlier. Each coefficient is less than or equal to maxlongint.

Output Format

Several products. The answer should also follow the usual writing style. For convenience in grading, if the answer is expressed as \((x+a)(x+b)\), then \( a > b \).

What is the usual writing style?

  1. \((x+0)\) is written as \( x \)
  2. \((x+a)(x+a)\) is written as \((x+a)^2\)
  3. Sometimes it can be written like this: \((x-3)\). However, expressions like \((x+-3)\) are not allowed.

Sample Input and Output

Sample Input #1

x^2-4

Sample Output #1

(x+2)(x-2)
// Not allowed to write as (x-2)(x+2) or (x+2)(x+-2)

Sample Input #2

x^2+5x+4

Sample Output #2

(x+4)(x+1)
// Not allowed to write as (x+1)(x+4)

Sample Input #3

x^2-2x+1

Sample Output #3

(x-1)^2

Sample Input #4

x^2+x

Sample Output #4

(x+1)x
// The reverse is not allowed.

Notes

The exponent of \( x \) does not exceed 2, and the number of terms does not exceed 3, in descending order of powers.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
x^2-4
样例输出
(x+2)(x-2) //而不能写成(x-2)(x+2)或者(x+2)(x+-2)