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
#include <cstdio>
#include <cstring>
#include <strings.h>
#include <deque>

typedef unsigned int smallnum;


int jerry_fls(smallnum v) {
  int r = 1;

  while (v >>= 1) {
    r++;
  }

  return r;
}


void print_representation(smallnum k) {
  int high_bit = jerry_fls(k);
  // Because of problem setting, high bit must be at least one
  std::deque<const char*> string_builder;

  string_builder.push_back("1"); // For the first bit in

  for (int i = high_bit - 2; i >= 0; i--) {
    smallnum check_bit = (1u << i);

    if (k & check_bit) {
      string_builder.push_front("(");
      string_builder.push_back("*(1+1)+1)");
    } else {
      string_builder.push_front("(");
      string_builder.push_back("*(1+1))");
    }
  }

  for (std::deque<const char*>::iterator i = string_builder.begin(); i != string_builder.end(); i++) {
    printf("%s", *i);
  }
  printf("\n");
}

int main() {
  smallnum t;
  scanf("%u\n", &t);

  for (smallnum i = 0; i < t; i++) {
    smallnum k;
    scanf("%u\n", &k);
    print_representation(k);
  }

  return 0;
}