#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define ppb pop_back #define eb emplace_back #define e1 first #define e2 second #define Ufor(a, b, i) for(int i=a;i<b; ++i) #define Dfor(a, b, i) for(int i=a;i>=b; --i) typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<pii, pii> pp; const int mod=1e9+7; const int inf=1e9+9; const int mod69=1e9+696969; #define maxn 1000010 int t[maxn],n; void nawias1() { printf("("); } void nawias2() { printf(")"); } void chuck1() { printf("(1+1)*"); } void chuck2() { printf("+1)"); } void jed(ll w) { ll r[31]; int k=0,roz=0; Dfor(30, 0, i) { if( (ll) (1<<i) <= w && w!=0) r[roz]=i, w-=(1<<i),roz++; } Ufor(0, roz/2, i) { ll p=r[i]; ll o=r[roz-i-1]; r[i]=o; r[roz-i-1]=p; } ///Ufor(0, roz, i) printf("%lld ", r[i]); int roz1=0; int d=0; int wyn=0; if(r[0]==0) d++; Ufor(d, roz, i) { if(i!=0) k=r[i-1]; Ufor(0, r[i]-k, j) { if(r[i]-k==1 && roz-1==i) printf("1+1"); else if(roz-1==i && r[i]-k-1==j) printf("(1+1)"),wyn+=2; else chuck1(),wyn+=2; } if(roz-1>i && r[i]-k!=0) nawias1(),roz1++; } Ufor(0, roz1, i) { chuck2(); wyn++; } if(r[0]==0) printf("+1"),wyn++; ///printf("\n%d\n", wyn); } int main() { ///cout<<(1<<3); int q; scanf("%d", &q); Ufor(0, q, i) { ll w; scanf("%lld", &w); jed(w);puts(""); } }
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | #include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define ppb pop_back #define eb emplace_back #define e1 first #define e2 second #define Ufor(a, b, i) for(int i=a;i<b; ++i) #define Dfor(a, b, i) for(int i=a;i>=b; --i) typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<pii, pii> pp; const int mod=1e9+7; const int inf=1e9+9; const int mod69=1e9+696969; #define maxn 1000010 int t[maxn],n; void nawias1() { printf("("); } void nawias2() { printf(")"); } void chuck1() { printf("(1+1)*"); } void chuck2() { printf("+1)"); } void jed(ll w) { ll r[31]; int k=0,roz=0; Dfor(30, 0, i) { if( (ll) (1<<i) <= w && w!=0) r[roz]=i, w-=(1<<i),roz++; } Ufor(0, roz/2, i) { ll p=r[i]; ll o=r[roz-i-1]; r[i]=o; r[roz-i-1]=p; } ///Ufor(0, roz, i) printf("%lld ", r[i]); int roz1=0; int d=0; int wyn=0; if(r[0]==0) d++; Ufor(d, roz, i) { if(i!=0) k=r[i-1]; Ufor(0, r[i]-k, j) { if(r[i]-k==1 && roz-1==i) printf("1+1"); else if(roz-1==i && r[i]-k-1==j) printf("(1+1)"),wyn+=2; else chuck1(),wyn+=2; } if(roz-1>i && r[i]-k!=0) nawias1(),roz1++; } Ufor(0, roz1, i) { chuck2(); wyn++; } if(r[0]==0) printf("+1"),wyn++; ///printf("\n%d\n", wyn); } int main() { ///cout<<(1<<3); int q; scanf("%d", &q); Ufor(0, q, i) { ll w; scanf("%lld", &w); jed(w);puts(""); } } |