import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class jed { public static void main(String[] args) throws IOException { InputScanner is = new InputScanner(); int t = is.nextInt(); for (int i = 0; i < t; i++) { int n = is.nextInt(); oneCnt = 0; if (n == 1) System.out.println("1"); else { String ans = constructAns(n); if (ans == null) System.out.println("NIE"); else System.out.println(ans); } } } static int oneCnt; private static String constructAns(int n) { if (oneCnt > 100) return null; if (n % 2 == 0) { oneCnt += 2; if (n / 2 > 1) return "(1+1)*" + constructAns(n / 2); else return "(1+1)"; } else { oneCnt += 3; if (n / 2 > 1) return "(1 +(1+1)*" + constructAns(n / 2) + ")"; else return "(1+1+1)"; } } static class InputScanner { BufferedReader br; StringTokenizer st; public InputScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() throws IOException { if (st == null || !st.hasMoreTokens()) { String line = br.readLine(); st = new StringTokenizer(line); } return st.nextToken(); } public int nextInt() throws IOException { String next = next(); return Integer.parseInt(next); } public long nextLong() throws IOException { String next = next(); return Long.parseLong(next); } } }
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 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class jed { public static void main(String[] args) throws IOException { InputScanner is = new InputScanner(); int t = is.nextInt(); for (int i = 0; i < t; i++) { int n = is.nextInt(); oneCnt = 0; if (n == 1) System.out.println("1"); else { String ans = constructAns(n); if (ans == null) System.out.println("NIE"); else System.out.println(ans); } } } static int oneCnt; private static String constructAns(int n) { if (oneCnt > 100) return null; if (n % 2 == 0) { oneCnt += 2; if (n / 2 > 1) return "(1+1)*" + constructAns(n / 2); else return "(1+1)"; } else { oneCnt += 3; if (n / 2 > 1) return "(1 +(1+1)*" + constructAns(n / 2) + ")"; else return "(1+1+1)"; } } static class InputScanner { BufferedReader br; StringTokenizer st; public InputScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() throws IOException { if (st == null || !st.hasMoreTokens()) { String line = br.readLine(); st = new StringTokenizer(line); } return st.nextToken(); } public int nextInt() throws IOException { String next = next(); return Integer.parseInt(next); } public long nextLong() throws IOException { String next = next(); return Long.parseLong(next); } } } |