#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
int a[] = { 1, 2,4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384 };
void divide(int n){
if (n == 0) return;
if (n == 1){
printf("2(0)");
return;
}
if (n == 2){
printf("2");
return;
}
int i = 14;
//找到最接近n的幂值
while (a[i] > n&&i >= 0)
i--;
printf("2");
if (i >= 2){
printf("(");
divide(i);
printf(")");
}
n -= a[i];
if (n)
printf("+");
divide(n);
}
int main(){
int N;
cin >> N;
divide(N);
// system("pause");
return 0;
}
网友评论