#include <bits/stdc++.h>
#include <stdint.h>
using namespace std;
void solve(int k, bool first=true) {
if(k == 0) return;
if(k == 1) { cout << "1"; return; }
if(k <= 5) {
if(not first) cout << "(";
cout << "1";
for(int i = 1; i < k; ++i) cout << "+1";
if(not first) cout << ")";
} else {
bool a = k & 1;
if(a and not first) cout << "(";
if(a) cout << "1+";
k >>= 1;
if(k == 0) return;
cout << "(1+1)";
if(k > 1) {
cout << "*";
solve(k, false);
}
if(a and not first) cout << ")";
}
}
void test() {
int k;
cin >> k;
solve(k);
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t --> 0) test();
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 | #include <bits/stdc++.h> #include <stdint.h> using namespace std; void solve(int k, bool first=true) { if(k == 0) return; if(k == 1) { cout << "1"; return; } if(k <= 5) { if(not first) cout << "("; cout << "1"; for(int i = 1; i < k; ++i) cout << "+1"; if(not first) cout << ")"; } else { bool a = k & 1; if(a and not first) cout << "("; if(a) cout << "1+"; k >>= 1; if(k == 0) return; cout << "(1+1)"; if(k > 1) { cout << "*"; solve(k, false); } if(a and not first) cout << ")"; } } void test() { int k; cin >> k; solve(k); cout << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while(t --> 0) test(); return 0; } |
English