#include<cstdio>
#include<string>
using namespace std;
const int D = 2;
const char jed[][10] = {"", "1", "(1+1)"};
string jedynki(int n)
{
if (n <= D) return jed[n];
string j = jedynki(n / D);
int r = n % D;
string s = r ? "(" : "";
if (j != "1") {
s += j;
s += "*";
}
s += jed[D];
if (r) {
s += "+";
s += jed[r];
s += ")";
}
return s;
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n;
scanf("%d", &n);
printf("%s\n", jedynki(n).c_str());
}
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 | #include<cstdio> #include<string> using namespace std; const int D = 2; const char jed[][10] = {"", "1", "(1+1)"}; string jedynki(int n) { if (n <= D) return jed[n]; string j = jedynki(n / D); int r = n % D; string s = r ? "(" : ""; if (j != "1") { s += j; s += "*"; } s += jed[D]; if (r) { s += "+"; s += jed[r]; s += ")"; } return s; } int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); printf("%s\n", jedynki(n).c_str()); } return 0; } |
English