#include <bits/stdc++.h>
using namespace std;
string s;
void f(int y)
{
if (y==0)
return;
if (y%2)
{
f(y-1);
if (s.size())
s="("+s+"+1)";
else
s="1";
}
else
{
f(y/2);
if (s.size())
s+="*(1+1)";
else
s="(1+1)";
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t, a;
cin>>t;
for(int I=0; I<t; I++)
{
cin>>a;
s.clear();
f(a);
cout<<s<<"\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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <bits/stdc++.h> using namespace std; string s; void f(int y) { if (y==0) return; if (y%2) { f(y-1); if (s.size()) s="("+s+"+1)"; else s="1"; } else { f(y/2); if (s.size()) s+="*(1+1)"; else s="(1+1)"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t, a; cin>>t; for(int I=0; I<t; I++) { cin>>a; s.clear(); f(a); cout<<s<<"\n"; } return 0; } |
English