#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
int t;
scanf("%d" , &t);
vector <int> stos;
for(int i=0;i<t;++i)
{
int n;
scanf("%d", &n);
stos.push_back(10);
int jedynki=0,sztos=0;
while(n>=2)
{
if(n%2==1)
{
stos.push_back(1);
--n;
++jedynki;
++sztos;
}
n=n/2;
++sztos;
stos.push_back(2);
}
for(int j=0;j<jedynki;++j)
{
printf("(");
}
for(int j=sztos;j>0;--j)
{
if(stos[j]==2)
{
printf("(1+1)");
}
if(stos[j]==1) printf("+1)");
if(stos[j-1]==2) printf("*");
}
printf("\n");
stos.erase(stos.begin(),stos.end());
}
return 0;
}
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 38 39 40 41 42 43 44 45 46 47 | #include <iostream> #include <cstdio> #include <vector> using namespace std; int main() { int t; scanf("%d" , &t); vector <int> stos; for(int i=0;i<t;++i) { int n; scanf("%d", &n); stos.push_back(10); int jedynki=0,sztos=0; while(n>=2) { if(n%2==1) { stos.push_back(1); --n; ++jedynki; ++sztos; } n=n/2; ++sztos; stos.push_back(2); } for(int j=0;j<jedynki;++j) { printf("("); } for(int j=sztos;j>0;--j) { if(stos[j]==2) { printf("(1+1)"); } if(stos[j]==1) printf("+1)"); if(stos[j-1]==2) printf("*"); } printf("\n"); stos.erase(stos.begin(),stos.end()); } return 0; } |
English