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
#include <bits/stdc++.h>

using namespace std;

#define pb push_back

int n;
string answer;
vector <int> bit;

int main(){
	int quest;
	scanf("%d", &quest);
	while(quest--){
		bit.clear();
		answer.clear();

		scanf("%d", &n);
//		printf("%d\n", n);
		
		if(n == 1){
			puts("1");
			return 0;
		}
		
		while(n > 0){
			bit.pb(n%2);
			n /= 2;
		}
		
		for(int i = 0; i < bit.size(); ++i){
			if(i == bit.size() - 1){
				answer.pop_back();
				break;
			}
	
			int v = bit[i];
			if(v == 1){
				answer = answer + '(' + '1' + '+' + '(' + '1' + '+' + '1' + ')' + '*';
			}
			else{
				answer = answer + '(' + '1' + '+' + '1' + ')' + '*';
			}
		}
		
		int ile = 0;
		for(auto v: answer)
			if(v == '(')
				++ile;
			else if(v == ')')
				--ile;
		
		while(ile--)
			answer.pb(')');
		
		for(int i = 0; i < answer.size(); ++i)
			printf("%c", answer[i]);
		puts("");
	}
	
	return 0;
}