提交时间:2024-08-20 13:11:07
运行 ID: 168684
#include <bits/stdc++.h> #include <stdio.h> #define BASE 2 void convert(int n, int e) { int digit, quotient; if(e == 0) { if(n == 0) ; else if( n == 1) printf("2(0)"); else if(n == 2) printf("2"); else { convert(n / BASE, e+1); digit = n % BASE; if(digit) { printf("+"); convert(digit, e); } } } else { quotient = n / BASE; digit = n % BASE; if(quotient > 0) { convert(quotient, e+1); if(digit) printf("+"); } if(digit) { if(e == 1) printf("2"); else { printf("2("); convert(e, 0); printf(")"); } } } } int main(void) { int n; scanf("%d", &n); convert(n, 0); printf("\n"); return 0; }