結果
問題 | No.732 3PrimeCounting |
ユーザー | tenten |
提出日時 | 2023-01-31 15:15:19 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,097 ms / 3,000 ms |
コード長 | 2,247 bytes |
コンパイル時間 | 2,438 ms |
コンパイル使用メモリ | 92,092 KB |
実行使用メモリ | 55,092 KB |
最終ジャッジ日時 | 2024-06-30 18:06:52 |
合計ジャッジ時間 | 22,329 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
50,192 KB |
testcase_01 | AC | 51 ms
50,404 KB |
testcase_02 | AC | 52 ms
50,416 KB |
testcase_03 | AC | 52 ms
50,380 KB |
testcase_04 | AC | 52 ms
50,424 KB |
testcase_05 | AC | 53 ms
50,380 KB |
testcase_06 | AC | 52 ms
50,396 KB |
testcase_07 | AC | 51 ms
50,280 KB |
testcase_08 | AC | 52 ms
50,152 KB |
testcase_09 | AC | 52 ms
50,272 KB |
testcase_10 | AC | 52 ms
50,488 KB |
testcase_11 | AC | 51 ms
50,492 KB |
testcase_12 | AC | 52 ms
50,240 KB |
testcase_13 | AC | 50 ms
50,096 KB |
testcase_14 | AC | 50 ms
50,376 KB |
testcase_15 | AC | 53 ms
50,408 KB |
testcase_16 | AC | 52 ms
50,404 KB |
testcase_17 | AC | 52 ms
50,392 KB |
testcase_18 | AC | 51 ms
50,148 KB |
testcase_19 | AC | 51 ms
50,540 KB |
testcase_20 | AC | 59 ms
50,252 KB |
testcase_21 | AC | 93 ms
52,316 KB |
testcase_22 | AC | 92 ms
51,872 KB |
testcase_23 | AC | 53 ms
50,392 KB |
testcase_24 | AC | 52 ms
50,432 KB |
testcase_25 | AC | 103 ms
52,500 KB |
testcase_26 | AC | 104 ms
52,324 KB |
testcase_27 | AC | 68 ms
51,212 KB |
testcase_28 | AC | 82 ms
51,300 KB |
testcase_29 | AC | 82 ms
51,440 KB |
testcase_30 | AC | 75 ms
51,528 KB |
testcase_31 | AC | 97 ms
51,780 KB |
testcase_32 | AC | 109 ms
52,084 KB |
testcase_33 | AC | 98 ms
52,724 KB |
testcase_34 | AC | 108 ms
52,632 KB |
testcase_35 | AC | 95 ms
51,932 KB |
testcase_36 | AC | 93 ms
52,260 KB |
testcase_37 | AC | 56 ms
50,492 KB |
testcase_38 | AC | 59 ms
50,560 KB |
testcase_39 | AC | 107 ms
52,048 KB |
testcase_40 | AC | 93 ms
52,352 KB |
testcase_41 | AC | 95 ms
51,936 KB |
testcase_42 | AC | 98 ms
52,192 KB |
testcase_43 | AC | 89 ms
51,900 KB |
testcase_44 | AC | 74 ms
51,432 KB |
testcase_45 | AC | 70 ms
51,264 KB |
testcase_46 | AC | 75 ms
51,132 KB |
testcase_47 | AC | 72 ms
51,300 KB |
testcase_48 | AC | 119 ms
52,696 KB |
testcase_49 | AC | 105 ms
52,748 KB |
testcase_50 | AC | 96 ms
52,256 KB |
testcase_51 | AC | 96 ms
51,980 KB |
testcase_52 | AC | 80 ms
51,376 KB |
testcase_53 | AC | 114 ms
52,628 KB |
testcase_54 | AC | 426 ms
52,632 KB |
testcase_55 | AC | 425 ms
52,888 KB |
testcase_56 | AC | 436 ms
52,572 KB |
testcase_57 | AC | 149 ms
52,584 KB |
testcase_58 | AC | 154 ms
52,528 KB |
testcase_59 | AC | 117 ms
52,744 KB |
testcase_60 | AC | 184 ms
52,772 KB |
testcase_61 | AC | 184 ms
52,744 KB |
testcase_62 | AC | 542 ms
52,396 KB |
testcase_63 | AC | 275 ms
52,600 KB |
testcase_64 | AC | 218 ms
52,704 KB |
testcase_65 | AC | 217 ms
52,612 KB |
testcase_66 | AC | 54 ms
50,028 KB |
testcase_67 | AC | 55 ms
50,596 KB |
testcase_68 | AC | 464 ms
52,776 KB |
testcase_69 | AC | 464 ms
52,824 KB |
testcase_70 | AC | 421 ms
52,592 KB |
testcase_71 | AC | 465 ms
55,092 KB |
testcase_72 | AC | 259 ms
52,576 KB |
testcase_73 | AC | 821 ms
54,784 KB |
testcase_74 | AC | 836 ms
54,680 KB |
testcase_75 | AC | 104 ms
52,660 KB |
testcase_76 | AC | 456 ms
52,724 KB |
testcase_77 | AC | 156 ms
52,804 KB |
testcase_78 | AC | 663 ms
52,796 KB |
testcase_79 | AC | 483 ms
52,808 KB |
testcase_80 | AC | 582 ms
52,684 KB |
testcase_81 | AC | 444 ms
52,664 KB |
testcase_82 | AC | 66 ms
50,904 KB |
testcase_83 | AC | 160 ms
52,632 KB |
testcase_84 | AC | 166 ms
52,640 KB |
testcase_85 | AC | 418 ms
55,088 KB |
testcase_86 | AC | 606 ms
52,748 KB |
testcase_87 | AC | 1,020 ms
54,548 KB |
testcase_88 | AC | 1,097 ms
54,856 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 + 1]; 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 * 3 + 1]; long ans = 0; for (int i = 2; primes.get(i) <= n; i++) { for (int j = 0; j < i - 1; j++) { counts[primes.get(i - 1) + primes.get(j)]++; } for (int j = i + 1; j < primes.size(); 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(); } }