#include <bits/stdc++.h> using namespace std; vector<bool> V; int main(){ ios_base::sync_with_stdio(0); int t; cin >> t; for(int i = 0; i < t; i++){ V.clear(); int n; cin >> n; if(n == 1){ cout << "1\n"; continue; } while(n > 0){ V.push_back(n % 2); n /= 2; } int nawiasy = V.size() - 1; string wyn = ""; if(V[V.size() - 2] == 0){ nawiasy--; } for(int j = 0; j < nawiasy; j++){ wyn += "("; } for(int j = V.size() - 2; j >= 0; j--){ if(V[j]){ wyn += "(1+1)+1)*"; } else{ if(j == V.size() - 2){ wyn += "(1+1)*"; } else{ wyn += "(1+1))*"; } } } wyn.pop_back(); cout << wyn << "\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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include <bits/stdc++.h> using namespace std; vector<bool> V; int main(){ ios_base::sync_with_stdio(0); int t; cin >> t; for(int i = 0; i < t; i++){ V.clear(); int n; cin >> n; if(n == 1){ cout << "1\n"; continue; } while(n > 0){ V.push_back(n % 2); n /= 2; } int nawiasy = V.size() - 1; string wyn = ""; if(V[V.size() - 2] == 0){ nawiasy--; } for(int j = 0; j < nawiasy; j++){ wyn += "("; } for(int j = V.size() - 2; j >= 0; j--){ if(V[j]){ wyn += "(1+1)+1)*"; } else{ if(j == V.size() - 2){ wyn += "(1+1)*"; } else{ wyn += "(1+1))*"; } } } wyn.pop_back(); cout << wyn << "\n"; } return 0; } |