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
#include <iostream>
#include <string>
#include <list>
using namespace std;


int main()
{
	int test; 	// liczba testow
	cin >> test;
	
	for(int i = 0; i < test; ++i)
	{
		list<char> result;
		int number, counter = 0;
		cin >> number;
		
		int power;
		for(power = 0; 1<<(power+1) <= number; ++power);
		
		for(; power >= 0; --power)
		{
			if(number & 1<<power)
			{
				
				if(result.empty()) result.push_back('1');
				else 
				{
					result.push_front('(');
					result.push_back('+');
					result.push_back('1');
					result.push_back(')');
				}				
				counter++;
			}
			if(power > 0)
			{
				// Multiply all by 2
				result.push_back('*');
				result.push_back('(');
				result.push_back('1');
				result.push_back('+');
				result.push_back('1');
				result.push_back(')');
				counter += 2;
			}
		}
		string output;
		output.insert(output.begin(), result.begin(), result.end());
		if(counter > 100) cout << "NIE" << endl;
		else cout << output << endl;			
	}
	
	return 0;
}