405804: GYM102114 C Call It What You Want

Memory Limit:0 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Call It What You Wanttime limit per test2 secondsmemory limit per test256 mebibytesinputstandard inputoutputstandard output

As a stereotyped math fanatic, Taylor is expert on utilizing scientific computing tools but he is poor at programming infrastructures, which brings him endless powerlessness.

Recently he worked on factoring polynomials of the form (xn - 1) over the integers, which aims to express any polynomial of that form as some product of irreducible factors whose coefficients are all in the integers.

With knowledge of the cyclotomic polynomial, he has known that where each factor of that is just an irreducible polynomial over the integers. Moreover, , where is the unit complex root of degree n and is the greatest common divisor of n and k.

Although he found such a conclusion, he couldn't obtain the result of some high-degree polynomial in a few seconds. Could you please help him accomplish some factorizations of (xn - 1)?

Here are some examples:

  • Φ1(x) = x - 1;
  • Φ2(x) = x + 1, x2 - 1 = (x - 1)(x + 1);
  • Φ3(x) = x2 + x + 1, x3 - 1 = (x - 1)(x2 + x + 1);
  • Φ4(x) = x2 + 1, x4 - 1 = (x - 1)(x + 1)(x2 + 1);
  • Φ6(x) = x2 - x + 1, x6 - 1 = (x - 1)(x + 1)(x2 - x + 1)(x2 + x + 1);
  • Φ12(x) = x4 - x2 + 1, x12 - 1 = (x - 1)(x + 1)(x2 - x + 1)(x2 + 1)(x2 + x + 1)(x4 - x2 + 1).

Oops! You might have some observations such as the degree of Φn(x) equals to φ(n), coefficients of Φn(x) are the same back-to-front as front-to-back except for Φ1(x), when p is prime, etc. , but they might be worthless for solving.

Input

The first line contains one integer T, indicating the number of test cases.

Each of the following T lines describes a test case and contains only one integer n.

1 ≤ T ≤ 100, 2 ≤ n ≤ 105.

It is guaranteed that the sum of n in all test cases does not exceed 5·106.

Output

For each test case, output the factorization as a string without any space in one line, where the polynomials should be sorted in a particular order and each polynomial should be printed in a particular format and enclosed in a pair of parentheses.

Order of polynomials: The order of polynomial f(x) is lower than that of polynomial g(x) if and only if there exists a non-negative integer m such that the coefficient of xk (k = m + 1, m + 2, ...) in f(x) equals to that of g(x) but the coefficient of xm in f(x) is less than that of g(x).

Output format of one polynomial: Output all the terms of the polynomial from high-degree to low-degree, each of which should be formed as  ± ckxk. Additionally,

  1. One term should be omitted if its coefficient is zero.
  2. The sign of the first term ( ± ) should be omitted if the coefficient of that item is positive.
  3. When ck = 1, ck should be omitted unless k = 0.
  4. x0 should be omitted while x1 should be written as a simple x.

It is guaranteed that the size of the standard output file does not exceed 26 MiB.

ExampleInput
5
2
3
4
6
12
Output
(x-1)(x+1)
(x-1)(x^2+x+1)
(x-1)(x+1)(x^2+1)
(x-1)(x+1)(x^2-x+1)(x^2+x+1)
(x-1)(x+1)(x^2-x+1)(x^2+1)(x^2+x+1)(x^4-x^2+1)

加入题单

算法标签: