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
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <vector>
using namespace std;

typedef long long int LL;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int t;
  std::cin >> t;
  for (int i = 0; i < t; i++) {
    LL a;
    std::cin >> a;
    std::vector<pair<LL, int>> number;
    LL isOk = 0;
    if (a <= 100) {
      for (int j = 0; j < a - 1; j++) {
        std::cout << "1+";
      }
      std::cout << "1\n";
      continue;
    } else {
      LL r = 0;
      LL res = a;
      int z = 0;
      while (res >= 2 || res >= 5) {
        if (z % 2 == 0) {
          r = res % 2;
          res = res / 2;
          isOk = isOk + 2 + r;
          number.push_back(make_pair(2, r));
        } else {
          r = res % 5;
          res = res / 5;
          isOk = isOk + 5 + r;
          number.push_back(make_pair(5, r));
        }
        z++;
      }
    }
    if (isOk > 100) {
      std::cout << "NIE\n";
    } else {
      int naw = 0;
      for (int k = 0; k < number.size(); ++k) {
        if (k != 0 && k != number.size() - 1) {
          std::cout << "(";
          naw++;
        }
        std::cout << "(";
        for (int u = 0; u < number[k].first - 1; ++u) {
          std::cout << "1+";
        }
        if (k < number.size() - 1) {
          std::cout << "1)*";
        } else {
          std::cout << "1)";
        }
      }
      int sz = number.size() - 1;
      for (int k = naw; k > 0; --k, --sz) {
        if (number[sz].second == 0)
          std::cout << ")";
        else if (number[sz].second == 1) {
          std::cout << "+1)";
        } else {
          std::cout << "+";
          for (int u = number[sz].second - 1; u > 0; --u) {
            std::cout << "1+";
          }
          std::cout << "1)";
        }
      }
      if (number[0].second != 0) {
        std::cout << "+";
        for (int k = number[0].second - 1; k > 0; --k) {
          std::cout << "1+";
        }
        std::cout << "1";
      }
      std::cout << '\n';
    }
  }
  return 0;
}