#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(0);
int t;
cin >> t;
for (int i = 0; i < t; ++i)
{
ll n;
cin >> n;
if (n == 1)
{
cout << "1" << endl;
continue;
}
string bity = "";
for (ll j = 32; j >= 0; --j)
{
if ((n & (1LL << j)) > 0) bity += "1";
else if (bity.size() != 0) bity += "0";
}
string odp = "";
if (bity[0] == '1' && bity[1] == '0') odp += "(1*(1+1))";
if (bity[0] == '1' && bity[1] == '1') odp += "(1*(1+1)+1)";
for (int j = 2; j < bity.size(); ++j)
{
if (bity[j] == '0') odp += "*(1+1)";
else odp += "*(1+1)+1";
odp = "(" + odp + ")";
}
cout << odp << 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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <iostream> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); int t; cin >> t; for (int i = 0; i < t; ++i) { ll n; cin >> n; if (n == 1) { cout << "1" << endl; continue; } string bity = ""; for (ll j = 32; j >= 0; --j) { if ((n & (1LL << j)) > 0) bity += "1"; else if (bity.size() != 0) bity += "0"; } string odp = ""; if (bity[0] == '1' && bity[1] == '0') odp += "(1*(1+1))"; if (bity[0] == '1' && bity[1] == '1') odp += "(1*(1+1)+1)"; for (int j = 2; j < bity.size(); ++j) { if (bity[j] == '0') odp += "*(1+1)"; else odp += "*(1+1)+1"; odp = "(" + odp + ")"; } cout << odp << endl; } return 0; } |
English