标签:算法训练 2的次幂表示
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> using namespace std; void count(int n){ while(n){ int k=n,m,e=0; while(k){ if(k%2==1){ m=e; } k/=2; e++; } n-=pow(2,m); if(m==1){if(n==0)printf("2");else printf("2+");} else if(m==2){if(n==0)printf("2(2)");else printf("2(2)+");} else if(m==0){printf("2(0)");} else { printf("2(");count(m);if(n==0)printf(")");else printf(")+"); } } } int main() { int n; while(scanf("%d",&n)==1){ count(n); printf("\n"); } return 0; }
标签:算法训练 2的次幂表示
原文地址:http://blog.csdn.net/r1986799047/article/details/43563877