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
73
74
75
76
77
78
#include <stdint.h>
#include <inttypes.h>
#include <math.h>
#include <stdio.h>

uint32_t cur_num, limit;
int ones_count = 1;
char buf[1000];
int length = 0;
char *ptr = buf;

void reset(){
    length = 0;
    ptr = buf;
}

void print(){
    buf[length] = 0;
    printf("%s\n", (length > 1)? buf+2 : buf);
}

void append(char* s){
    while(*s){
        *(ptr++) = *(s++);
        ++length;
    }
}

void print_as_ones(uint32_t num){
    if((ones_count += num) > 100)
        return;
    for(;num > 1;--num){
        append("1+");
    }
    append("1");
    ++ones_count;
}

void breakdown_and_print(){
    reset();
    int div;
    limit = floor(sqrt(cur_num));
    append("1");
    ones_count = 1;
    for (div=2; div <= limit; ++div){
        if (cur_num % div == 0){
            append("*(");
            print_as_ones(div);
            append(")");
            cur_num = cur_num / div;
            --div;
            if(ones_count > 100)
                return;
        }
    }
    if(cur_num > 1){
        append("*(");
        print_as_ones(cur_num);
        append(")");
    }
    if(ones_count <= 100){
        print();
    } else {
        puts("NIE");
    };
}

int main(){
    int count;

    scanf("%d", &count);
    while(count > 0){
        scanf("%" SCNu32 "", &cur_num);
        breakdown_and_print();
        --count;
    }
    return 0;
}