#include<iostream> #include<stack> #include<algorithm> #include<cmath> using namespace std; const int N=100002; stack <int> stos; int n, i, t, k,dwojki; void gen(int k){ while(k>1) { dwojki++; stos.push(k%2); k = k/2; } } int main() { ios_base::sync_with_stdio(0); cin >> t; while(t--){ cin >> n; dwojki = 0; gen(n); for(i = 0; i < dwojki; ++i) { cout <<"(1+1)*"; if(i<dwojki-1) cout<<"("; } cout<<"1"; while(!stos.empty()){ if(stos.top()==1) cout<<"+1"; if(stos.size()>1) cout<<")"; stos.pop(); } cout << endl; } 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 | #include<iostream> #include<stack> #include<algorithm> #include<cmath> using namespace std; const int N=100002; stack <int> stos; int n, i, t, k,dwojki; void gen(int k){ while(k>1) { dwojki++; stos.push(k%2); k = k/2; } } int main() { ios_base::sync_with_stdio(0); cin >> t; while(t--){ cin >> n; dwojki = 0; gen(n); for(i = 0; i < dwojki; ++i) { cout <<"(1+1)*"; if(i<dwojki-1) cout<<"("; } cout<<"1"; while(!stos.empty()){ if(stos.top()==1) cout<<"+1"; if(stos.size()>1) cout<<")"; stos.pop(); } cout << endl; } return 0; } |