⛴李恒旭⚔♆§ • 1年前
using namespace std;
int bin[20], m;
void my_power(int n) {
int i;
int flag = 0;
while (n) {
for (i = m; i >= 0; i--) {
if (bin[i] <= n) {
n = n - bin[i];
if (flag == 0) {
flag = 1;
} else {
cout << "+";
}
if (i > 1) {
cout << "2(";
my_power(i);
cout << ")";
}
if (i == 1) {
cout << "2";
}
if (i == 0) {
cout << "2(0)";
}
}
}
}
}
int main() {
int n, i, j;
cin >> n;
m = 0;
bin[0] = 1;
while (bin[m] < n) {
m++;
bin[m] = bin[m - 1] * 2;
}
my_power(n);
return 0;
}
评论:
请先登录,才能进行评论