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

int main()
{
    ios_base::sync_with_stdio( false );
    cin.tie( nullptr );

    int t;
    cin>>t;

    while( t-- )
    {
        string result;

        int k;
        cin >> k;

        bool firstBit = true;
        int openingBraces = 0;

        while( k > 1 )
        {
            if( k % 2 == 1 )
            {
                if( !firstBit )
                {
                    result += "(";
                    ++openingBraces;
                }
                result += "1+";
            }
            k /= 2;

            result += "(1+1)";

            if( k > 1 )
                result += "*";

            firstBit = false;
        }

        result.append( openingBraces, ')' );

        if( result.size() == 0 )
            cout << "1\n";
        else
            cout << result << "\n";
    }

    return 0;
}