//第一题(100%) public static void string() { Scanner in = new Scanner(System.in); int N = Integer.parseInt(in.nextLine()); String inputStr = in.nextLine(); if (inputStr.length() != N) return; char[] str = inputStr.toCharArray(); int sum = 0; for (int i = 0; i < N / 2; i++) { if (str[i] != str[N - 1 - i]) sum++; } System.out.println(sum); } //第二题(100%) static void map() { Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int i = 0; i < T; i++) { long N = in.nextLong(), M = in.nextLong(); if ((N * M) % 2 == 0) System.out.println(2); else { long max = M * N; boolean flag = false; for (int j = 2; j < max; j++) { if (max % j == 0) { max = j; flag = true; break; } } if (flag) System.out.println(max); else { System.out.println(Math.min(N, M)); } } } } //第三题(80%) static void primeNumber() { Scanner in = new Scanner(System.in); int m = in.nextInt(), n = in.nextInt(); int p = 0, q = Math.abs((m - n)) + 1; for (int i = m; i <= n; i++) { if (isPrimeNumber(i)) { p++; } } int max = 1; for (int i = 2; i < p; i++) { if (p % i == 0 && q % i == 0) { max = i; } } System.out.printf("%d %d", p / max, q / max); } static boolean isPrimeNumber(int num) { double sqrtNum = Math.sqrt(num); for (int i = 2; i < sqrtNum; i++) { if (num % i == 0) { return false; } } return true; }
全部评论
(2) 回帖