1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;

const int MAXP = 31623;

int Z[MAXP + 1];
vector<int> LP;

void generuj_liczby_pierwsze() {
	Z[0] = Z[1] = 1;
	for (int i = 2; i <= MAXP; ++i) {
		if (Z[i]) {
			continue;
		}
		LP.push_back(i);
		for (int j = i * i; j <= MAXP; j += i) {
			Z[j] = 1;
		}
	}
}

string generuj_rownanie(int n) {
	string r = "";
	if (n < 6) {
		r = "1";
		for (int i = 1; i < n; ++i) {
			r += "+1";
		}
		return r;
	}
	int a = n;
	for (int i = 0; i < (int)LP.size() && LP[i] * LP[i] <= n && a > 1; ++i) {
		while (a % LP[i] == 0) {
			if (r.size() > 0) {
				r += "*";
			}
			r += "(" + generuj_rownanie(LP[i]) + ")";
			a /= LP[i];
		}
	}
	if (a == n) {
		return "1+(" + generuj_rownanie(n - 1) + ")";
	}
	if (a > 1) {
		if (r.size() > 0) {
			r += "*";
		}
		r += "(" + generuj_rownanie(a) + ")";
	}
	return r;
}

int main() {
	generuj_liczby_pierwsze();
	int t, k;
	string r;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &k);
		r = generuj_rownanie(k);
		k = 0;
		for (int i = 0; i < (int)r.size(); ++i) {
			k += r[i] == '1';
		}
		if (k > 100) {
			puts("NIE");
		} else {
			puts(r.c_str());
		}
	}
	return 0;
}