#include <bits/stdc++.h> #define FOR(a, b, c) for(int a=b; a<=(c); a++) using namespace std; int main(){ ios_base::sync_with_stdio(false); int q; cin >> q; while(q--){ int x; cin >> x; int licz=0; int jed=0; while(x>1){ if(x%2==1) {cout << "(1+"; licz++; jed++;} cout << "(1+1)"; jed+=2; x/=2; if(x>1) cout << "*"; } FOR(i, 1, licz) cout << ")"; cout << "\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 | #include <bits/stdc++.h> #define FOR(a, b, c) for(int a=b; a<=(c); a++) using namespace std; int main(){ ios_base::sync_with_stdio(false); int q; cin >> q; while(q--){ int x; cin >> x; int licz=0; int jed=0; while(x>1){ if(x%2==1) {cout << "(1+"; licz++; jed++;} cout << "(1+1)"; jed+=2; x/=2; if(x>1) cout << "*"; } FOR(i, 1, licz) cout << ")"; cout << "\n"; } } |