1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int a,b,t,k,bits[30],bitswlk;
    char txt[10000];

    scanf("%d",&t);
    for (a=0; a<t; a++)
    {
       scanf("%d",&k);
       if (k==1) strcpy(txt,"1");
        else
        {
            bitswlk=0;

            while (k>0)
            {
                bits[bitswlk++]=k&1;
                k=k>>1;
            }
            strcpy(txt,"");
            for (b=0; b<bitswlk-2; b++) strcat(txt,"(");
            for (b=bitswlk-1; b>=0; b--)
            {
                if ((b<bitswlk-1)&&(bits[b]==1)) strcat(txt,"+1");
                if ((b>0)&&(b<bitswlk-1)) strcat(txt,")*(1+1)");
                if ((b>0)&&(b==bitswlk-1)) strcat(txt,"1+1");
            }
        }
        printf("%s\n",txt);
    }

    return 0;
}