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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class jed {

    public static void main(String[] args) {

        try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int t = Integer.parseInt(reader.readLine());
            StringBuilder output = new StringBuilder();

            for (int i = 0; i < t; i++) {
                resolveCase(Integer.parseInt(reader.readLine()), output);
            }

            System.out.println(output);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void resolveCase(int number, StringBuilder output) {

        if (number == 1) {
            output.append(1).append("\n");
            return;
        }

        int onesCounter = 0;
        String result = performDividing(number);
        char[] resultChars = result.toCharArray();

        for (char i = 0; i < resultChars.length; i++) {
            if (resultChars[i] == '1') {
                onesCounter++;
            }
        }

        if (onesCounter > 100) {
            output.append("NIE\n");
            return;
        }

        output.append(result).append("\n");
    }

    private static String performDividing(int number) {
        if (number == 1) {
            return "1";
        }
        if (number == 2) {
            return "1+1";
        }
        if (number == 3) {
            return "1+1+1";
        }

        if (number % 2 == 0) {
            return "(" + performDividing(number/2) + ")*(1+1)";
        }
        if (number % 3 == 0) {
            return "(" + performDividing(number/3) + ")*(1+1+1)";
        }

        return "(" + performDividing((number-1)/2) + ")*(1+1)+1";
    }

}