这代码太柯爱了
查看原帖
这代码太柯爱了
814343
bc2_cryeggy楼主2023/2/11 09:53

代码:

#include<bits/stdc++.h>
using namespace std;
const int logn = 16.2877;
#define qwq ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int a[logn + 1];

void f(int n)
{
	if (n == 0)
		return;
	int i;
	for (i = logn; i >= 1; i --)
	{
		if (a[i] < n)
			break;
	}
	if (i == 0)
		cout << "2(0)";
	else if (i == 1)
		cout << "2";
	else if (i > 1)
	{
		cout << "2(";
		f(i);
		cout << ")";
	}
	if (n > a[i])
	{
		cout << "+";
		f(n - a[i]);
	}
}

int main()
{
	qwq;
	int n;
	cin >> n;
	a[0] = 1;
	for (int i = 1; i <= 16; i++)
	{
		a[i] = a[i-1] * 2; 
	}
	f(n); 
	return 0;
}

2023/2/11 09:53
加载中...