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
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int t, k;
vector <string> digits;
void prepare();
void solve();
void solve_bin();

int main() {
  prepare();
  scanf("%d", &t);
  while(t--) {
    scanf("%d", &k);
    solve_bin();
  }
  return 0;
}

void solve() {
  int act = 0;
  vector <int> r;
  while(k > 0) {
    r.push_back(k % 10);
    k /= 10;
    act += 1;
  }

  for(int i = 0; i < act - 1; ++i) printf("(");
  printf("%s", digits[r[r.size() - 1]].c_str());
  for(int i = r.size() - 2; i >= 0; --i) {
    printf("*%s", digits[10].c_str());
    if(r[i] != 0) printf("+%s", digits[r[i]].c_str());
    printf(")");
  }
  puts("");
}

void solve_bin() {
  vector <int> r;
  for(int i = 0; i < 31; ++i) {
    if(k & (1 << i)) {
      r.push_back(1);
    } else r.push_back(0);
  }
  while(r.size() and r[r.size() - 1] == 0) r.pop_back();
  int act = r.size();
  
  for(int i = 0; i < act - 1; ++i) printf("(");
  printf("%s", digits[r[r.size() - 1]].c_str());
  for(int i = r.size() - 2; i >= 0; --i) {
    printf("*%s", digits[2].c_str());
    if(r[i] != 0) printf("+%s", digits[r[i]].c_str());
    printf(")");
  }
  puts("");
}

void prepare() {
  digits.push_back("");
  digits.push_back("1");
  digits.push_back("(1+1)");
  digits.push_back("(1+1+1)");
  digits.push_back("(1+1+1+1)");
  digits.push_back("(1+1+1+1+1)");
  digits.push_back("(1+1)*(1+1+1)");
  digits.push_back("((1+1)*(1+1+1)+1)");
  digits.push_back("(1+1)*(1+1)*(1+1)");
  digits.push_back("(1+1+1)*(1+1+1)");
  digits.push_back("(1+1)*(1+1+1+1+1)");
}