#include <bits/stdc++.h>
using namespace std;
string rob(int v)
{
if (v==1)
return "1";
if ((v&1) || (v==2))
return "("+rob(v-1)+"+"+rob(1)+")";
else
return "("+rob(v/2)+"*"+rob(2)+")";
}
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
cout << rob(n) << endl;
}
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 | #include <bits/stdc++.h> using namespace std; string rob(int v) { if (v==1) return "1"; if ((v&1) || (v==2)) return "("+rob(v-1)+"+"+rob(1)+")"; else return "("+rob(v/2)+"*"+rob(2)+")"; } int main() { int t; cin >> t; while(t--) { int n; cin >> n; cout << rob(n) << endl; } return 0; } |
English