【题解】洛谷P1010幂次方[NOIP1998普及] 分治
程序员文章站
2022-03-02 22:50:02
...
#include<cstdio>
void work(int x)
{
if(x==0){putchar('0');return;}
if(x==1){printf("2(0)");return;}
if(x==2){putchar('2');return;}
int i=0;
while((1<<i)<=x)i++;i--;
if(i!=1){printf("2(");work(i);putchar(')');}
else putchar('2');
if(x!=(1<<i)){putchar('+');work(x-(1<<i));}
}
int main()
{
int n;
scanf("%d",&n);
work(n);
return 0;
}