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
#ifdef _MSC_VER
  #ifndef __GNUC__
    #pragma warning(disable: 4996)
  #endif
  #define main main0
#endif
#include <iostream>
using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  do {
    int n, number = 0, ones = 0, i = 0, tab[100];
    cin >> n;
    if((n & 1) > 0) {
      tab[i++] = 1;
      --n;
      ++ones;
      ++number;
    } else {
      tab[i++] = 2;
      n /= 2;
      number += 2;
    }
    while(n > 1) {
      if((n & 1) > 0) {
        tab[i++] = 1;
        --n;
        ++ones;
      }
      if(n > 1) {
        tab[i++] = 2;
        n /= 2;
      }
    }
    for(int j = 0; j < ones; ++j)
      cout << '(';
    if(tab[--i] == 1) {
      cout << "1";
      ++number;
    } else {
      cout << "(1+1)";
      number += 2;
    }
    if(number > 100)
      cout << "NIE";
    else {
      while(--i >= 0) {
        if(tab[i] == 1) {
          cout << "+1)";
          ++number;
        } else {
          cout << "*(1+1)";
          number += 2;
        }
      }
    }
//cout << '\t' << number;
    cout << '\n';
  } while(--t > 0);
  return 0;
}