#include <bits/stdc++.h> using namespace std; int n; void solve(int x) { if(x == 1) { printf("1"); return; } if(x != n) printf("("); if(x & 1) printf("1+"); printf("(1+1)*"); solve(x / 2); if(x != n) printf(")"); } int main() { int t; scanf("%d", &t); while(t--) { scanf("%d", &n); solve(n); printf("\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 | #include <bits/stdc++.h> using namespace std; int n; void solve(int x) { if(x == 1) { printf("1"); return; } if(x != n) printf("("); if(x & 1) printf("1+"); printf("(1+1)*"); solve(x / 2); if(x != n) printf(")"); } int main() { int t; scanf("%d", &t); while(t--) { scanf("%d", &n); solve(n); printf("\n"); } return 0; } |