// // Created by Michal Stobierski on 23.11.16. // #include <iostream> #include <bits/stdc++.h> using namespace std; void print2pow(int k, bool last_mult) { int i; for (i = 1; i <= k-1; ++i){ cout << "(1+1)*"; } for (; i <= k; ++i) { if (last_mult) cout << "(1+1)*"; else cout << "(1+1)"; } } void solve(int n) { if (n == 1) { cout << "1" << endl; return; } vector< int > nonzero; int actPow = 0; while (n>0) { if (n&1) nonzero.push_back(actPow); n>>=1; ++actPow; } for (int i = 0; i < nonzero.size(); ++i) { if (i < nonzero.size()-1) { print2pow(nonzero[i], true); cout << "(1+"; } else { print2pow(nonzero[i], false); } for (int j = i+1; j < nonzero.size(); ++j) { nonzero[j] -= nonzero[i]; } } for (int i = 0; i < nonzero.size()-1; ++i) { cout << ")"; } cout << endl; return; } int main() { ios_base::sync_with_stdio(false); int numOfTasks; cin >> numOfTasks; while(numOfTasks--) { int n; cin >> n; solve(n); } 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 | // // Created by Michal Stobierski on 23.11.16. // #include <iostream> #include <bits/stdc++.h> using namespace std; void print2pow(int k, bool last_mult) { int i; for (i = 1; i <= k-1; ++i){ cout << "(1+1)*"; } for (; i <= k; ++i) { if (last_mult) cout << "(1+1)*"; else cout << "(1+1)"; } } void solve(int n) { if (n == 1) { cout << "1" << endl; return; } vector< int > nonzero; int actPow = 0; while (n>0) { if (n&1) nonzero.push_back(actPow); n>>=1; ++actPow; } for (int i = 0; i < nonzero.size(); ++i) { if (i < nonzero.size()-1) { print2pow(nonzero[i], true); cout << "(1+"; } else { print2pow(nonzero[i], false); } for (int j = i+1; j < nonzero.size(); ++j) { nonzero[j] -= nonzero[i]; } } for (int i = 0; i < nonzero.size()-1; ++i) { cout << ")"; } cout << endl; return; } int main() { ios_base::sync_with_stdio(false); int numOfTasks; cin >> numOfTasks; while(numOfTasks--) { int n; cin >> n; solve(n); } return 0; } |