#include "bits/stdc++.h" using namespace std; void print_unary(int k, bool is_factor = false){ if(k == 1) {cout << "1"; return;} if(k%2 && is_factor) cout << "("; if(k%2) cout << "1+"; cout << "(1+1)*"; print_unary(k/2, true); if(k%2 && is_factor) cout << ")"; } int main(){ int t, k; ios_base::sync_with_stdio(0); cin.tie(0); cin >> t; while(t--){ cin >> k; print_unary(k); cout << "\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 | #include "bits/stdc++.h" using namespace std; void print_unary(int k, bool is_factor = false){ if(k == 1) {cout << "1"; return;} if(k%2 && is_factor) cout << "("; if(k%2) cout << "1+"; cout << "(1+1)*"; print_unary(k/2, true); if(k%2 && is_factor) cout << ")"; } int main(){ int t, k; ios_base::sync_with_stdio(0); cin.tie(0); cin >> t; while(t--){ cin >> k; print_unary(k); cout << "\n"; } return 0; } |