import java.io.*;
import java.util.*;
public class jed {
public static String N2 = "(1 + 1)";
public static class IN {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = null;
private void prepare() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
}
public int getInt() throws IOException {
prepare();
return Integer.parseInt(st.nextToken());
}
public long getLong() throws IOException {
prepare();
return Long.parseLong(st.nextToken());
}
public String getString() throws IOException {
prepare();
return st.nextToken();
}
}
public static String solve(int k) {
ArrayList<Integer> bin = new ArrayList<>(31);
while (k>0) {
int m = k & 1;
k = k >> 1;
bin.add(m);
}
int N = bin.size();
if (N == 1) {
return "1";
}
StringBuilder prefix = new StringBuilder();
StringBuilder suffix = new StringBuilder();
if (bin.get(N - 2) == 0) {
suffix.append("1+1");
} else {
suffix.append("(1+1)+1");
}
for (int i=bin.size() - 3; i>=0; i--) {
prefix.append("(1+1)*(");
suffix.append(")");
if (bin.get(i) == 1) {
suffix.append("+1");
}
}
prefix.append(suffix);
return prefix.toString();
}
public static void main(String[] args) throws IOException {
IN in = new IN();
int t = in.getInt();
while (t-- > 0 ) {
System.out.println(solve(in.getInt()));
}
}
}
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | import java.io.*; import java.util.*; public class jed { public static String N2 = "(1 + 1)"; public static class IN { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = null; private void prepare() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } public int getInt() throws IOException { prepare(); return Integer.parseInt(st.nextToken()); } public long getLong() throws IOException { prepare(); return Long.parseLong(st.nextToken()); } public String getString() throws IOException { prepare(); return st.nextToken(); } } public static String solve(int k) { ArrayList<Integer> bin = new ArrayList<>(31); while (k>0) { int m = k & 1; k = k >> 1; bin.add(m); } int N = bin.size(); if (N == 1) { return "1"; } StringBuilder prefix = new StringBuilder(); StringBuilder suffix = new StringBuilder(); if (bin.get(N - 2) == 0) { suffix.append("1+1"); } else { suffix.append("(1+1)+1"); } for (int i=bin.size() - 3; i>=0; i--) { prefix.append("(1+1)*("); suffix.append(")"); if (bin.get(i) == 1) { suffix.append("+1"); } } prefix.append(suffix); return prefix.toString(); } public static void main(String[] args) throws IOException { IN in = new IN(); int t = in.getInt(); while (t-- > 0 ) { System.out.println(solve(in.getInt())); } } } |
English