#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int n=0;
int x=0;
scanf("%d",&n);
for(int j=0;j<n;j++){
scanf("%d",&x);
int ileNawiasow = 0;
string s1 = "*(1+1)";
string s2 = "*(1+(1+1)";
if (x == 1)
printf("1\n");
else {
if (x % 2 == 0) {
printf("(1+1)");
x /= 2;
} else {
printf("1+(1+1)");
x--;
x /= 2;
}
while (x > 1) {
if (x % 2 == 0) {
printf(s1.c_str());
x /= 2;
} else {
printf(s2.c_str());
x--;
x /= 2;
ileNawiasow++;
}
}
for (int j = 0; j < ileNawiasow; j++)
printf(")");
printf("\n");
}
}
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 <stdio.h> using namespace std; int main() { int n=0; int x=0; scanf("%d",&n); for(int j=0;j<n;j++){ scanf("%d",&x); int ileNawiasow = 0; string s1 = "*(1+1)"; string s2 = "*(1+(1+1)"; if (x == 1) printf("1\n"); else { if (x % 2 == 0) { printf("(1+1)"); x /= 2; } else { printf("1+(1+1)"); x--; x /= 2; } while (x > 1) { if (x % 2 == 0) { printf(s1.c_str()); x /= 2; } else { printf(s2.c_str()); x--; x /= 2; ileNawiasow++; } } for (int j = 0; j < ileNawiasow; j++) printf(")"); printf("\n"); } } return 0; } |
English