#include <iostream> #include <cassert> #include <string> using namespace std; int main(int argc, char *argv[]) { ios_base::sync_with_stdio(false); int t; cin >> t; for(int i=0; i<t; i++) { uint32_t K; cin >> K; assert(1 <= K); uint32_t k = K; int j; string s; int ones = 0; for(j=0;j<31;j++,k<<=1) { if(k & 1U<<31) { s="1"; ones++; k<<=1; break; } } for(;j<31;j++,k<<=1) { if(k & 1U<<31) { s = "((1+1)*" + s + "+1)"; ones+=3; } else { s = "(1+1)*" + s; ones+=2; } } cout << s << "\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 <cassert> #include <string> using namespace std; int main(int argc, char *argv[]) { ios_base::sync_with_stdio(false); int t; cin >> t; for(int i=0; i<t; i++) { uint32_t K; cin >> K; assert(1 <= K); uint32_t k = K; int j; string s; int ones = 0; for(j=0;j<31;j++,k<<=1) { if(k & 1U<<31) { s="1"; ones++; k<<=1; break; } } for(;j<31;j++,k<<=1) { if(k & 1U<<31) { s = "((1+1)*" + s + "+1)"; ones+=3; } else { s = "(1+1)*" + s; ones+=2; } } cout << s << "\n"; } return 0; } |