import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class jed {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
List<Integer> toCalculate = new ArrayList<>();
for(int i = 0; i < t; i++){
toCalculate.add(sc.nextInt());
}
for(int i = 0; i < toCalculate.size(); i++){
String result = "";
int target = toCalculate.get(i);
if(target==1){
System.out.println(1);
} else {
int braceCount=0;
int count =0;
while (target != 1 || count>100) {
if (target % 2 != 0) {
target--;
result = result + "1+";
count+=1;
} else {
if(target == 2){
result += "1+1*(";
braceCount++;
count += 2;
} else {
result += "(1+1)*(";
braceCount++;
count += 2;
}
target /= 2;
}
}
if(count > 100){
System.out.println("NIE");
} else {
result = result.subSequence(0, result.length() - 2).toString();
for (int j = 0; j < braceCount - 1; j++) {
result += ")";
}
System.out.println(result);
}
}
}
}
}
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 | import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class jed { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); List<Integer> toCalculate = new ArrayList<>(); for(int i = 0; i < t; i++){ toCalculate.add(sc.nextInt()); } for(int i = 0; i < toCalculate.size(); i++){ String result = ""; int target = toCalculate.get(i); if(target==1){ System.out.println(1); } else { int braceCount=0; int count =0; while (target != 1 || count>100) { if (target % 2 != 0) { target--; result = result + "1+"; count+=1; } else { if(target == 2){ result += "1+1*("; braceCount++; count += 2; } else { result += "(1+1)*("; braceCount++; count += 2; } target /= 2; } } if(count > 100){ System.out.println("NIE"); } else { result = result.subSequence(0, result.length() - 2).toString(); for (int j = 0; j < braceCount - 1; j++) { result += ")"; } System.out.println(result); } } } } } |
English