// Krzysztof Małysa
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,n) for (int i = (a), i##__ = (n); i <= i##__; ++i)
#define REP(i,n) FOR(i,0,n-1)
#define FORD(i,a,n) for (int i = (a), i##__ = (n); i >= i##__; --i)
#define ALL(x) x.begin(), x.end()
#define EB emplace_back
#define ST first
#define ND second
#define OO(A) template<class... T> ostream& operator<<(ostream& os, const A<T...>& x) { return __o(os, ALL(x)); }
#define SZ(x) ((int)x.size())
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<PII> VPII;
template<class A, class B> ostream& operator<<(ostream&, const pair<A, B>&);
template<class I> ostream& __o(ostream&, I, I);
template<class T, size_t N> ostream& operator<<(ostream& os, const array<T, N>& x) { return __o(os, ALL(x)); }
OO(vector) OO(deque) OO(set) OO(multiset) OO(map) OO(multimap)
template<class A, class B> ostream& operator<<(ostream& os, const pair<A, B>& p) {
return os << "(" << p.ST << ", " << p.ND << ")";
}
template<class I> ostream& __o(ostream& os, I a, I b) {
os << "{";
for (; a != b;)
os << *a++, cerr << (a == b ? "" : " ");
return os << "}";
}
template<class I> ostream& __d(ostream& os, I a, I b) {
os << "{\n";
for (I c = a; a != b; ++a)
os << " " << distance(c, a) << ": " << *a << endl;
return os << "}";
}
template<class... T> void __e(T&&... a) {
int t[] = {(cerr << forward<T>(a), 0)...}; (void)t;
cerr << endl;
}
template<class A, class B> void mini(A& a, B&& b) { if (b < a) a = b; }
template<class A, class B> void maxi(A& a, B&& b) { if (b > a) a = b; }
int ceil2(int x) { return 1 << (sizeof(x) * 8 - __builtin_clz(x - 1)); }
#ifdef DEBUG
# define D(...) __VA_ARGS__
#else
# define D(...)
#endif
#define LOG(x) D(cerr << #x ": " << x)
#define LOGN(x) D(LOG(x) << endl)
#define DUMP(x) D(cerr << #x ": ", __d(cerr, ALL(x)) << endl)
#define E(...) D(__e(__VA_ARGS__))
#define endl '\n'
constexpr char nl = '\n';
// End of templates
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int z;
cin >> z;
while (z--) {
int n;
cin >> n;
if (n == 1) {
cout << 1 << nl;
continue;
}
int k = 0; // # of parenthesis to close
string expr;
while (n > 1) {
if (n & 1) {
expr += "(1+";
++k;
}
expr += "(1+1)*";
n >>= 1;
}
expr.pop_back();
cout << expr;
while (k--)
cout << ')';
cout << nl;
}
return 0;
}
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 93 94 | // Krzysztof Małysa #include <bits/stdc++.h> using namespace std; #define FOR(i,a,n) for (int i = (a), i##__ = (n); i <= i##__; ++i) #define REP(i,n) FOR(i,0,n-1) #define FORD(i,a,n) for (int i = (a), i##__ = (n); i >= i##__; --i) #define ALL(x) x.begin(), x.end() #define EB emplace_back #define ST first #define ND second #define OO(A) template<class... T> ostream& operator<<(ostream& os, const A<T...>& x) { return __o(os, ALL(x)); } #define SZ(x) ((int)x.size()) typedef long long LL; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<PII> VPII; template<class A, class B> ostream& operator<<(ostream&, const pair<A, B>&); template<class I> ostream& __o(ostream&, I, I); template<class T, size_t N> ostream& operator<<(ostream& os, const array<T, N>& x) { return __o(os, ALL(x)); } OO(vector) OO(deque) OO(set) OO(multiset) OO(map) OO(multimap) template<class A, class B> ostream& operator<<(ostream& os, const pair<A, B>& p) { return os << "(" << p.ST << ", " << p.ND << ")"; } template<class I> ostream& __o(ostream& os, I a, I b) { os << "{"; for (; a != b;) os << *a++, cerr << (a == b ? "" : " "); return os << "}"; } template<class I> ostream& __d(ostream& os, I a, I b) { os << "{\n"; for (I c = a; a != b; ++a) os << " " << distance(c, a) << ": " << *a << endl; return os << "}"; } template<class... T> void __e(T&&... a) { int t[] = {(cerr << forward<T>(a), 0)...}; (void)t; cerr << endl; } template<class A, class B> void mini(A& a, B&& b) { if (b < a) a = b; } template<class A, class B> void maxi(A& a, B&& b) { if (b > a) a = b; } int ceil2(int x) { return 1 << (sizeof(x) * 8 - __builtin_clz(x - 1)); } #ifdef DEBUG # define D(...) __VA_ARGS__ #else # define D(...) #endif #define LOG(x) D(cerr << #x ": " << x) #define LOGN(x) D(LOG(x) << endl) #define DUMP(x) D(cerr << #x ": ", __d(cerr, ALL(x)) << endl) #define E(...) D(__e(__VA_ARGS__)) #define endl '\n' constexpr char nl = '\n'; // End of templates int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int z; cin >> z; while (z--) { int n; cin >> n; if (n == 1) { cout << 1 << nl; continue; } int k = 0; // # of parenthesis to close string expr; while (n > 1) { if (n & 1) { expr += "(1+"; ++k; } expr += "(1+1)*"; n >>= 1; } expr.pop_back(); cout << expr; while (k--) cout << ')'; cout << nl; } return 0; } |
English