[2017騰訊校招線上筆試題]
阿新 • • 發佈:2018-12-26
import java.util.ArrayList; import java.util.Scanner; public class Main { public static ArrayList<Integer> rst = new ArrayList<Integer>(); public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { rst = new ArrayList<>(); int input = in.nextInt(); search(input); print(); } } public static void search(int target) { int start = -90; int end = 90; while (rst.size() < 6) { int mid = (start + end) / 2; if (target < mid) { rst.add(0); end = mid; } else { rst.add(1); start = mid; } } } public static void print() { for (int each : rst) { System.out.print(each); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int input = in.nextInt(); int count = 0; for (int i = 2; i <= input / 2; i++) { if (isZhi(i) && isZhi(input - i)) { System.out.print(i); System.out.println(input - i); count++; } } System.out.println(count); } public static boolean isZhi(int tar) { if (tar < 2) { return false; } for (int i = 2; i * i <= tar; i++) { if (tar % i == 0) { return false; } } return true; } }