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
import java.util.Scanner;

public class jed {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int tests = scanner.nextInt();
        String[] results = new String[tests];
        for (int t = 0; t < tests; t++) {
            results[t] = solve(scanner.nextInt());
        }

        for (int t = 0; t < tests; t++) {
            System.out.println(results[t]);
        }
    }

    private static String solve(int number) {
        if (number == 1) {
            return String.valueOf(number);
        }

        String binary = Integer.toBinaryString(number);
        int[] levels = new int[binary.length() - 1];
        int counter = 0;
        for (int i = 1; i < binary.length(); i++) {
            int digits = binary.charAt(i) == '0' ? 2 : 3;
            levels[i - 1] = digits;
            counter += digits;
            if (counter > 100) {
                return "NIE";
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = levels.length - 1; i >= 0; i--) {
            if (levels[i] == 2) {
                sb.append(i == 0 ? "1+1" : "(1+1)");
            } else {
                sb.append(i == 0 ? "1+1+1" : "1+(1+1)");
            }
            if (i != 0) {
                sb.append("*(");
            }
        }
        for (int i = 0; i < levels.length - 1; i++) {
            sb.append(")");
        }
        return sb.toString();
    }
}