#include <iostream>
using namespace std;
string go(int k){
if(k == 1) return "1";
if(k%2 == 0)
return "("+go(k/2) + "*(1+1))";
else return "(" + go(k/2) + "*(1+1)+1)";
}
int main() {
int t;
scanf("%d", &t);
while(t--) {
int k;
scanf("%d",&k);
cout << go(k) << endl;
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <iostream> using namespace std; string go(int k){ if(k == 1) return "1"; if(k%2 == 0) return "("+go(k/2) + "*(1+1))"; else return "(" + go(k/2) + "*(1+1)+1)"; } int main() { int t; scanf("%d", &t); while(t--) { int k; scanf("%d",&k); cout << go(k) << endl; } return 0; } |
English