#include <iostream>
#include <string>
#include <bitset>
using namespace std;
int main()
{
int t, k;
cin >> t;
while (t-- > 0) {
cin >> k;
string s = bitset<32>(k).to_string();
string ans = "";
if (k == 1) ans = "1";
if (k == 2) ans = "(1+1)";
if (k > 2) {
ans = "(1+1)";
int start = s.find('1');
for (int i = start+1; i < 31; i++) {
if (s[i] == '1') ans = "(" + ans + "+1)*(1+1)";
else ans = ans + "*(1+1)";
}
}
if (s[31] == '1' && k != 1) ans = ans + "+1";
cout << ans << endl;
}
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 | #include <iostream> #include <string> #include <bitset> using namespace std; int main() { int t, k; cin >> t; while (t-- > 0) { cin >> k; string s = bitset<32>(k).to_string(); string ans = ""; if (k == 1) ans = "1"; if (k == 2) ans = "(1+1)"; if (k > 2) { ans = "(1+1)"; int start = s.find('1'); for (int i = start+1; i < 31; i++) { if (s[i] == '1') ans = "(" + ans + "+1)*(1+1)"; else ans = ans + "*(1+1)"; } } if (s[31] == '1' && k != 1) ans = ans + "+1"; cout << ans << endl; } return 0; } |
English