//
// Created by pierre on 23.11.16.
//
#include <iostream>
#include <stack>
#include <queue>
void solve(int k);
void simpleSolve(int k);
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
int ilez;
cin >> ilez;
int k;
for (int aa = 0; aa < ilez; aa++)
{
cin >> k;
solve(k);
cout << endl;
}
}
void solve(int k)
{
if ( k <= 100)
{
simpleSolve(k);
}
else
{
queue<int> q;
int opening = 0;
for (int i = 30; i >= 0; i--)
{
if (q.empty())
{
if (k & (1 << i))
{
q.push(0);
}
}
else
{
q.push(2);
if (k & (1 << i))
{
q.push(1);
opening++;
}
}
}
for (int i = 0; i < opening; i++)
{
cout << "(";
}
int tmp;
while (!q.empty())
{
tmp = q.front();
q.pop();
if (tmp == 1)
{
cout<<"+1)";
}
else if(tmp == 2)
{
cout<<"*(1+1)";
}
else
{
cout<<"1";
}
}
}
}
void simpleSolve(int k)
{
for (int i = 0; i < k; i++)
{
if (i > 0) cout << "+";
cout << "1";
}
}
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | // // Created by pierre on 23.11.16. // #include <iostream> #include <stack> #include <queue> void solve(int k); void simpleSolve(int k); using namespace std; int main() { ios_base::sync_with_stdio(0); int ilez; cin >> ilez; int k; for (int aa = 0; aa < ilez; aa++) { cin >> k; solve(k); cout << endl; } } void solve(int k) { if ( k <= 100) { simpleSolve(k); } else { queue<int> q; int opening = 0; for (int i = 30; i >= 0; i--) { if (q.empty()) { if (k & (1 << i)) { q.push(0); } } else { q.push(2); if (k & (1 << i)) { q.push(1); opening++; } } } for (int i = 0; i < opening; i++) { cout << "("; } int tmp; while (!q.empty()) { tmp = q.front(); q.pop(); if (tmp == 1) { cout<<"+1)"; } else if(tmp == 2) { cout<<"*(1+1)"; } else { cout<<"1"; } } } } void simpleSolve(int k) { for (int i = 0; i < k; i++) { if (i > 0) cout << "+"; cout << "1"; } } |
English