#include<cstdio> #include<iostream> #include<string> using namespace std; int T,n; string solve(int n){ if(n==1)return "1"; if(n==2)return "1+1"; if(n&1)return solve(n-1)+"+1"; return "("+solve(n>>1)+")*(1+1)"; } int main(){ cin>>T; while(T--){ cin>>n; cout<<solve(n)<<endl; } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include<cstdio> #include<iostream> #include<string> using namespace std; int T,n; string solve(int n){ if(n==1)return "1"; if(n==2)return "1+1"; if(n&1)return solve(n-1)+"+1"; return "("+solve(n>>1)+")*(1+1)"; } int main(){ cin>>T; while(T--){ cin>>n; cout<<solve(n)<<endl; } return 0; } |