#include<stdio.h> #include<math.h> void solve(int n) { int cnt=0; while(pow(2,cnt)<=n) cnt++; cnt--; if(cnt==0) printf("2(0)"); else if(cnt==1) printf("2"); else { printf("2("); solve(cnt); printf(")"); } int num_r=n-pow(2,cnt); if(num_r) { printf("+"); solve(num_r); } } int main() { int n; while(~scanf("%d",&n)) { solve(n); printf("\n"); } return 0; } /************************************************************** Problem: 1095 User: kirchhoff Language: C Result: Accepted Time:0 ms Memory:1004 kb ****************************************************************/
原文地址:http://blog.csdn.net/wdkirchhoff/article/details/42246349