#include <iostream>
std::string shortest(int k){
if(k==1){
return "1";
}
std::string res = shortest(k/2);
if(res != std::string("1")){
res = (std::string("(1+1)*") + "(" + res + ")");
}
else{
res = "1+1";
}
if(k%2 == 1){
res += "+1";
}
return res;
}
int main(){
int z;
std::cin >> z;
while(z--){
int n;
std::cin >> n;
std::cout << shortest(n) << std::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> std::string shortest(int k){ if(k==1){ return "1"; } std::string res = shortest(k/2); if(res != std::string("1")){ res = (std::string("(1+1)*") + "(" + res + ")"); } else{ res = "1+1"; } if(k%2 == 1){ res += "+1"; } return res; } int main(){ int z; std::cin >> z; while(z--){ int n; std::cin >> n; std::cout << shortest(n) << std::endl; } return 0; } |
English