#include <bits/stdc++.h> using namespace std; void int2out(int x){ if(x == 1){cout << "1"; return;} if(x == 2){cout << "1+1"; return;} if(x == 3){cout << "1+1+1"; return;} if(x/2 <= 0)return; if(x % 2 == 0){cout << "("; int2out(x/2); cout << ")*(1+1)";return;} if(x % 2 == 1){cout << "("; int2out(x/2); cout << ")*(1+1)+1";return;} return; } int main(){ ios_base::sync_with_stdio(0); int t; cin >> t; for(int n, i = 0; i < t; i++){ cin >> n; int2out(n); 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 | #include <bits/stdc++.h> using namespace std; void int2out(int x){ if(x == 1){cout << "1"; return;} if(x == 2){cout << "1+1"; return;} if(x == 3){cout << "1+1+1"; return;} if(x/2 <= 0)return; if(x % 2 == 0){cout << "("; int2out(x/2); cout << ")*(1+1)";return;} if(x % 2 == 1){cout << "("; int2out(x/2); cout << ")*(1+1)+1";return;} return; } int main(){ ios_base::sync_with_stdio(0); int t; cin >> t; for(int n, i = 0; i < t; i++){ cin >> n; int2out(n); cout << "\n"; } return 0; } |