#include<bits/stdc++.h> using namespace std; string solve(int k){ if(k==1)return "1"; string suf=""; if(k%2==1)suf="+1"; return "("+solve(k/2)+"*(1+1)"+suf+")"; } int main(){ int t; scanf("%d",&t); while(t--){ int k; scanf("%d",&k); cout<<solve(k)<<"\n"; } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include<bits/stdc++.h> using namespace std; string solve(int k){ if(k==1)return "1"; string suf=""; if(k%2==1)suf="+1"; return "("+solve(k/2)+"*(1+1)"+suf+")"; } int main(){ int t; scanf("%d",&t); while(t--){ int k; scanf("%d",&k); cout<<solve(k)<<"\n"; } return 0; } |