提交时间:2024-08-20 14:49:06
运行 ID: 168922
#include <bits/stdc++.h> #define BASE 2 void BDX(int n, int e){ int DJK, djk; if(e == 0) { if(n == 0) ; else if( n == 1) printf("2(0)"); else if(n == 2) printf("2"); else { BDX(n / BASE, e+1); DJK = n % BASE; if(DJK) { printf("+"); BDX(DJK, e); } } } else { djk = n / BASE; DJK = n % BASE; if(djk > 0) { BDX(djk, e+1); if(DJK) printf("+"); } if(DJK) { if(e == 1) printf("2"); else { printf("2("); BDX(e, 0); printf(")"); } } } } int main(void) { int n; scanf("%d", &n); BDX(n, 0); printf("\n"); return 0; }