#include <iostream>
#include <string>
#include <sstream>
int main() {
std::ios::sync_with_stdio(false);
std::string basic[] = {"", "1", "1+1", "1+1+1", "1+1+1+1", "1+1+1+1+1"};
int t;
std::cin >> t;
while(t--) {
int k,p=0;
std::stringstream ss;
std::cin >> k;
if (k<6) {
ss << basic[k];
} else {
while(k>=6) {
if (k&1) {
ss << "1+(1+1)";
} else {
ss << "(1+1)";
}
k >>= 1;
if (k > 1) {
ss << "*(";
p++;
}
}
if (k > 1) {
ss << basic[k];
}
while(p--) {
ss << ")";
}
}
std::cout << ss.str() << '\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 | #include <iostream> #include <string> #include <sstream> int main() { std::ios::sync_with_stdio(false); std::string basic[] = {"", "1", "1+1", "1+1+1", "1+1+1+1", "1+1+1+1+1"}; int t; std::cin >> t; while(t--) { int k,p=0; std::stringstream ss; std::cin >> k; if (k<6) { ss << basic[k]; } else { while(k>=6) { if (k&1) { ss << "1+(1+1)"; } else { ss << "(1+1)"; } k >>= 1; if (k > 1) { ss << "*("; p++; } } if (k > 1) { ss << basic[k]; } while(p--) { ss << ")"; } } std::cout << ss.str() << '\n'; } return 0; } |
English