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
#include <stdio.h>
#include <vector>
using namespace std;

const int max_prime = 32000;
bool sieve_primes[max_prime];
vector<int> primes;

void sieve() {
    sieve_primes[0]=sieve_primes[1]=true;
    for(int i=2;i<max_prime;i++)
        if(!sieve_primes[i]) {
            primes.push_back(i);
            for(int j=2*i;j<max_prime;j+=i)
                sieve_primes[j]=true;
        }
}

void factor(int n, vector<int> &f) {
    if(n==1) {
        f.push_back(1);
        return;
    }
    for(unsigned int i=0;i<primes.size();i++) {
        int prime = primes[i];
        while(n%prime == 0) {
            f.push_back(prime);
            n/=prime;
        }
    }
    if(n>1)
        f.push_back(n);
}

int main(int argc, char **argv)
{
	int t, ki;
    sieve();
    scanf("%d", &t);
    while(t--) {
        scanf("%d",&ki);
        vector<int> factors;
        factor(ki, factors);
        int num_ones=0;
        for(unsigned int i=0;i<factors.size();i++)
            num_ones+=factors[i];
        if(num_ones>100)
            printf("NIE");
        else
            for(unsigned int i=0;i<factors.size();i++) {
                putchar('(');
                for(int j=0;j<factors[i];j++) {
                    putchar('1');
                    if(j<factors[i]-1)
                        putchar('+');
                }
                putchar(')');
                if(i<factors.size()-1)
                    putchar('*');
            }
        putchar('\n');
    }
	return 0;
}