#include<bits/stdc++.h> #define lli long long #define mp make_pair #define sec second #define fst first #define pb push_back using namespace std; const int N=200010; //pair<int,int> x[N]; //pair<int,int> y[N]; //vector<int> kraw[N]; //int odw[N]; int main() { int q; scanf("%d", &q); while(q--) { int n; scanf("%d", &n); if(n==1) {printf("1\n"); continue;} int nawias=0; if(n%2==1) { printf("1+(1+1)");} else { printf("(1+1)"); //nawias++; } n/=2; while(n>=2) { if(n%2==1) { nawias++; printf("*(1+(1+1)");} else { printf("*(1+1)"); //nawias++; } n/=2; } //printf("(1+1)"); for(int i=1;i<=nawias;i++) printf(")"); printf("\n"); } }
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 | #include<bits/stdc++.h> #define lli long long #define mp make_pair #define sec second #define fst first #define pb push_back using namespace std; const int N=200010; //pair<int,int> x[N]; //pair<int,int> y[N]; //vector<int> kraw[N]; //int odw[N]; int main() { int q; scanf("%d", &q); while(q--) { int n; scanf("%d", &n); if(n==1) {printf("1\n"); continue;} int nawias=0; if(n%2==1) { printf("1+(1+1)");} else { printf("(1+1)"); //nawias++; } n/=2; while(n>=2) { if(n%2==1) { nawias++; printf("*(1+(1+1)");} else { printf("*(1+1)"); //nawias++; } n/=2; } //printf("(1+1)"); for(int i=1;i<=nawias;i++) printf(")"); printf("\n"); } } |