結果
問題 | No.732 3PrimeCounting |
ユーザー | tenten |
提出日時 | 2023-04-10 17:08:11 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 443 ms / 3,000 ms |
コード長 | 2,348 bytes |
コンパイル時間 | 2,643 ms |
コンパイル使用メモリ | 96,184 KB |
実行使用メモリ | 55,020 KB |
最終ジャッジ日時 | 2024-10-06 03:03:51 |
合計ジャッジ時間 | 17,370 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
50,088 KB |
testcase_01 | AC | 55 ms
50,068 KB |
testcase_02 | AC | 56 ms
50,368 KB |
testcase_03 | AC | 55 ms
50,596 KB |
testcase_04 | AC | 54 ms
50,160 KB |
testcase_05 | AC | 55 ms
50,104 KB |
testcase_06 | AC | 56 ms
50,104 KB |
testcase_07 | AC | 55 ms
50,596 KB |
testcase_08 | AC | 55 ms
50,612 KB |
testcase_09 | AC | 55 ms
50,572 KB |
testcase_10 | AC | 55 ms
50,052 KB |
testcase_11 | AC | 55 ms
50,192 KB |
testcase_12 | AC | 55 ms
50,372 KB |
testcase_13 | AC | 54 ms
50,080 KB |
testcase_14 | AC | 54 ms
50,216 KB |
testcase_15 | AC | 54 ms
50,032 KB |
testcase_16 | AC | 55 ms
50,088 KB |
testcase_17 | AC | 54 ms
49,968 KB |
testcase_18 | AC | 54 ms
50,564 KB |
testcase_19 | AC | 55 ms
50,496 KB |
testcase_20 | AC | 63 ms
50,320 KB |
testcase_21 | AC | 90 ms
51,412 KB |
testcase_22 | AC | 96 ms
51,756 KB |
testcase_23 | AC | 56 ms
50,012 KB |
testcase_24 | AC | 56 ms
49,964 KB |
testcase_25 | AC | 104 ms
52,792 KB |
testcase_26 | AC | 102 ms
52,392 KB |
testcase_27 | AC | 68 ms
50,908 KB |
testcase_28 | AC | 68 ms
50,884 KB |
testcase_29 | AC | 77 ms
51,548 KB |
testcase_30 | AC | 92 ms
51,636 KB |
testcase_31 | AC | 97 ms
51,896 KB |
testcase_32 | AC | 112 ms
52,392 KB |
testcase_33 | AC | 108 ms
52,556 KB |
testcase_34 | AC | 106 ms
52,424 KB |
testcase_35 | AC | 99 ms
52,320 KB |
testcase_36 | AC | 96 ms
52,500 KB |
testcase_37 | AC | 59 ms
50,248 KB |
testcase_38 | AC | 59 ms
50,404 KB |
testcase_39 | AC | 98 ms
52,124 KB |
testcase_40 | AC | 99 ms
52,048 KB |
testcase_41 | AC | 97 ms
51,992 KB |
testcase_42 | AC | 96 ms
52,216 KB |
testcase_43 | AC | 77 ms
51,516 KB |
testcase_44 | AC | 78 ms
51,556 KB |
testcase_45 | AC | 70 ms
50,980 KB |
testcase_46 | AC | 71 ms
50,932 KB |
testcase_47 | AC | 75 ms
51,492 KB |
testcase_48 | AC | 116 ms
53,012 KB |
testcase_49 | AC | 118 ms
53,056 KB |
testcase_50 | AC | 78 ms
51,732 KB |
testcase_51 | AC | 95 ms
51,952 KB |
testcase_52 | AC | 69 ms
50,808 KB |
testcase_53 | AC | 126 ms
53,032 KB |
testcase_54 | AC | 209 ms
52,844 KB |
testcase_55 | AC | 280 ms
53,192 KB |
testcase_56 | AC | 200 ms
52,824 KB |
testcase_57 | AC | 148 ms
53,076 KB |
testcase_58 | AC | 173 ms
53,960 KB |
testcase_59 | AC | 132 ms
53,080 KB |
testcase_60 | AC | 162 ms
52,984 KB |
testcase_61 | AC | 146 ms
52,968 KB |
testcase_62 | AC | 242 ms
52,928 KB |
testcase_63 | AC | 191 ms
52,952 KB |
testcase_64 | AC | 184 ms
53,124 KB |
testcase_65 | AC | 151 ms
52,948 KB |
testcase_66 | AC | 54 ms
50,104 KB |
testcase_67 | AC | 56 ms
49,980 KB |
testcase_68 | AC | 218 ms
53,052 KB |
testcase_69 | AC | 243 ms
53,152 KB |
testcase_70 | AC | 326 ms
53,612 KB |
testcase_71 | AC | 215 ms
52,944 KB |
testcase_72 | AC | 189 ms
53,316 KB |
testcase_73 | AC | 287 ms
52,752 KB |
testcase_74 | AC | 338 ms
52,932 KB |
testcase_75 | AC | 107 ms
52,756 KB |
testcase_76 | AC | 276 ms
53,152 KB |
testcase_77 | AC | 136 ms
52,860 KB |
testcase_78 | AC | 394 ms
52,980 KB |
testcase_79 | AC | 323 ms
53,032 KB |
testcase_80 | AC | 267 ms
53,180 KB |
testcase_81 | AC | 274 ms
52,836 KB |
testcase_82 | AC | 66 ms
50,760 KB |
testcase_83 | AC | 194 ms
54,180 KB |
testcase_84 | AC | 154 ms
53,104 KB |
testcase_85 | AC | 206 ms
53,048 KB |
testcase_86 | AC | 290 ms
53,104 KB |
testcase_87 | AC | 443 ms
54,904 KB |
testcase_88 | AC | 411 ms
55,020 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); boolean[] isNotPrimes = new boolean[n * 3]; ArrayList<Integer> primes = new ArrayList<>(); for (int i = 2; i < isNotPrimes.length; i++) { if (!isNotPrimes[i]) { primes.add(i); for (int j = 2; j * i < isNotPrimes.length; j++) { isNotPrimes[j * i] = true; } } } int[] counts = new int[n * 2]; long ans = 0; for (int i = 2; i < primes.size(); i++) { if (primes.get(i) > n) { break; } for (int j = 0; j < i - 1; j++) { counts[primes.get(j) + primes.get(i - 1)]++; } for (int j = i + 1; j < primes.size() && primes.get(j) < primes.get(i) * 3; j++) { ans += counts[primes.get(j) - primes.get(i)]; } } System.out.println(ans); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }