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
// jed.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>

using namespace std;

string my_i_to_str(int n, int base = 2) // for 2..10 only
{
	if(n < 0)
		return "-" + my_i_to_str(-n);
	if(n==0)
		return "0";
	string res;
	while(n > 0) {
		res.push_back('0' + (n%base));
		n /= base;
	}
	reverse(res.begin(), res.end());
	return res;
}

int main(int argc, char* argv[])
{
	int TEST_NUM;
	cin >> TEST_NUM;
	for(int the_test=0; the_test < TEST_NUM; the_test++) {
		int N;
		cin >> N;
		string s = my_i_to_str(N);
		string res = "1";
		for(size_t i = 1; i < s.size(); i++) {
			if(s[i]=='0')
				res += "*(1+1)";
			else
				res = "(" + res + "*(1+1)+1)";
		}
		cout << res << endl;
	}
	return 0;
}