import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class jed {
public void solve() throws IOException {
InputReader reader = new InputReader(System.in);
int t = reader.readInt();
for (int i = 0; i < t; i++) {
int l = reader.readInt();
String x = printRecursively(l);
System.out.println(x);
}
}
private String printRecursively(int l) {
if (l == 1)
return "1";
if ((l & 1) == 0)
return "((1+1)*" + printRecursively(l / 2) + ")";
else
return "((1+1)*" + printRecursively(l / 2) + "+1)";
}
public static void main(String[] args) throws IOException {
new jed().solve();
}
private static class InputReader {
private final BufferedReader reader;
private StringTokenizer tokenizer = new StringTokenizer("", " ");
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 100 * 1000);
}
String nextString() throws IOException {
if (!tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine(), " ");
return tokenizer.nextToken();
}
int readInt() throws IOException {
return Integer.parseInt(nextString());
}
}
}
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 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class jed { public void solve() throws IOException { InputReader reader = new InputReader(System.in); int t = reader.readInt(); for (int i = 0; i < t; i++) { int l = reader.readInt(); String x = printRecursively(l); System.out.println(x); } } private String printRecursively(int l) { if (l == 1) return "1"; if ((l & 1) == 0) return "((1+1)*" + printRecursively(l / 2) + ")"; else return "((1+1)*" + printRecursively(l / 2) + "+1)"; } public static void main(String[] args) throws IOException { new jed().solve(); } private static class InputReader { private final BufferedReader reader; private StringTokenizer tokenizer = new StringTokenizer("", " "); InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 100 * 1000); } String nextString() throws IOException { if (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine(), " "); return tokenizer.nextToken(); } int readInt() throws IOException { return Integer.parseInt(nextString()); } } } |
English