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
#include <iostream>
using integer = uint32_t;
std::string f( integer );
std::string f( integer n )
{
    std::string t[] = { "1", "1+1", "1+1+1" };
    if( n < 4 ) return t[n-1];
    else
    {
        std::string r { n & 1 ? "1+(1+1)*" : "(1+1)*" };
        integer p {};
        for( n >>= 1; n >= 4; n >>= 1 )
        {
            if( n & 1 )
            {
                r += "(1+(1+1)*";
                ++p;
            }
            else r += "(1+1)*";
        }
        r += "(" + t[n-1] + ")";
        std::string s( p, ')' );
        return r + s;
    }
    return "?";
}
int main()
{
    using namespace std;
    ios_base::sync_with_stdio( false );
    using test = uint16_t;
    test t;
    cin >> t;
    integer k;
    for( test i {}; i < t; ++i )
    {
        cin >> k;
        cout << f( k ) << endl;
    }
    return 0;
}