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
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main()
{
        int z, l;       // z-zestaw, l-liczba dla danego zestawu
        vector <int> v; // vector liczb;
        cin.sync_with_stdio(false);

        string S;
        cin >> z;
        for (int i = 0; i < z; ++i)
        {
                cin >> l;
                v.push_back(l);
        }
        for (int i = 0;i < v.size(); ++i)
        {
                S="1";
                if (v[i]==1)
                {
                        cout << 1 << endl;
                        continue;
                }

                int c=0;
                for (c=31; c>=0; --c)
                        if (v[i] & (1<<c)) break;   
                for (int j = c-1; j >= 0; --j)
                {
                        if (v[i] & (1 << j))
                                S="(" + S + ")*(1+1)+1";
                        else
                                S="(" + S + ")*(1+1)";
                }
                cout << S << endl;
        }
        return 0;
}