結果
問題 | No.732 3PrimeCounting |
ユーザー | tenten |
提出日時 | 2021-11-11 18:08:22 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,231 ms / 3,000 ms |
コード長 | 1,901 bytes |
コンパイル時間 | 2,172 ms |
コンパイル使用メモリ | 78,960 KB |
実行使用メモリ | 43,080 KB |
最終ジャッジ日時 | 2024-05-02 13:08:14 |
合計ジャッジ時間 | 22,770 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
37,072 KB |
testcase_01 | AC | 46 ms
37,140 KB |
testcase_02 | AC | 44 ms
37,140 KB |
testcase_03 | AC | 44 ms
36,960 KB |
testcase_04 | AC | 43 ms
36,872 KB |
testcase_05 | AC | 42 ms
37,132 KB |
testcase_06 | AC | 43 ms
36,944 KB |
testcase_07 | AC | 43 ms
37,028 KB |
testcase_08 | AC | 43 ms
36,564 KB |
testcase_09 | AC | 45 ms
37,140 KB |
testcase_10 | AC | 44 ms
37,072 KB |
testcase_11 | AC | 47 ms
36,736 KB |
testcase_12 | AC | 47 ms
36,860 KB |
testcase_13 | AC | 44 ms
37,072 KB |
testcase_14 | AC | 45 ms
37,012 KB |
testcase_15 | AC | 45 ms
37,080 KB |
testcase_16 | AC | 44 ms
36,856 KB |
testcase_17 | AC | 43 ms
36,996 KB |
testcase_18 | AC | 48 ms
36,736 KB |
testcase_19 | AC | 45 ms
36,860 KB |
testcase_20 | AC | 46 ms
36,948 KB |
testcase_21 | AC | 70 ms
37,872 KB |
testcase_22 | AC | 60 ms
38,116 KB |
testcase_23 | AC | 45 ms
37,000 KB |
testcase_24 | AC | 45 ms
37,168 KB |
testcase_25 | AC | 101 ms
39,356 KB |
testcase_26 | AC | 92 ms
39,164 KB |
testcase_27 | AC | 49 ms
37,068 KB |
testcase_28 | AC | 51 ms
37,032 KB |
testcase_29 | AC | 58 ms
37,492 KB |
testcase_30 | AC | 70 ms
37,484 KB |
testcase_31 | AC | 62 ms
37,968 KB |
testcase_32 | AC | 97 ms
39,828 KB |
testcase_33 | AC | 98 ms
39,292 KB |
testcase_34 | AC | 98 ms
39,504 KB |
testcase_35 | AC | 90 ms
38,940 KB |
testcase_36 | AC | 92 ms
38,864 KB |
testcase_37 | AC | 45 ms
36,780 KB |
testcase_38 | AC | 47 ms
37,148 KB |
testcase_39 | AC | 85 ms
39,384 KB |
testcase_40 | AC | 88 ms
39,000 KB |
testcase_41 | AC | 92 ms
38,704 KB |
testcase_42 | AC | 75 ms
38,704 KB |
testcase_43 | AC | 79 ms
38,268 KB |
testcase_44 | AC | 69 ms
37,844 KB |
testcase_45 | AC | 51 ms
37,032 KB |
testcase_46 | AC | 50 ms
36,608 KB |
testcase_47 | AC | 51 ms
36,912 KB |
testcase_48 | AC | 101 ms
39,336 KB |
testcase_49 | AC | 111 ms
39,076 KB |
testcase_50 | AC | 79 ms
38,280 KB |
testcase_51 | AC | 82 ms
38,352 KB |
testcase_52 | AC | 52 ms
37,244 KB |
testcase_53 | AC | 119 ms
39,788 KB |
testcase_54 | AC | 439 ms
40,116 KB |
testcase_55 | AC | 509 ms
43,080 KB |
testcase_56 | AC | 430 ms
40,220 KB |
testcase_57 | AC | 164 ms
42,180 KB |
testcase_58 | AC | 169 ms
42,344 KB |
testcase_59 | AC | 114 ms
39,716 KB |
testcase_60 | AC | 197 ms
42,116 KB |
testcase_61 | AC | 174 ms
39,816 KB |
testcase_62 | AC | 605 ms
42,628 KB |
testcase_63 | AC | 265 ms
39,824 KB |
testcase_64 | AC | 216 ms
41,460 KB |
testcase_65 | AC | 204 ms
39,828 KB |
testcase_66 | AC | 45 ms
36,720 KB |
testcase_67 | AC | 44 ms
37,224 KB |
testcase_68 | AC | 498 ms
39,848 KB |
testcase_69 | AC | 510 ms
39,932 KB |
testcase_70 | AC | 496 ms
42,888 KB |
testcase_71 | AC | 473 ms
42,848 KB |
testcase_72 | AC | 285 ms
42,548 KB |
testcase_73 | AC | 1,038 ms
43,076 KB |
testcase_74 | AC | 939 ms
43,060 KB |
testcase_75 | AC | 108 ms
39,408 KB |
testcase_76 | AC | 553 ms
40,320 KB |
testcase_77 | AC | 183 ms
42,272 KB |
testcase_78 | AC | 701 ms
40,048 KB |
testcase_79 | AC | 507 ms
40,156 KB |
testcase_80 | AC | 688 ms
42,780 KB |
testcase_81 | AC | 449 ms
39,664 KB |
testcase_82 | AC | 48 ms
36,952 KB |
testcase_83 | AC | 161 ms
42,400 KB |
testcase_84 | AC | 189 ms
42,376 KB |
testcase_85 | AC | 430 ms
40,400 KB |
testcase_86 | AC | 682 ms
42,888 KB |
testcase_87 | AC | 1,231 ms
40,644 KB |
testcase_88 | AC | 1,218 ms
40,304 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); boolean[] isNotPrime = new boolean[n * 3 + 1]; ArrayList<Integer> primes = new ArrayList<>(); for (int i = 3; i <= n * 3; i += 2) { if (isNotPrime[i]) { continue; } for (int j = 3; j * i <= n * 3; j += 2) { isNotPrime[j * i] = true; } if (i <= n) { primes.add(i); } } long ans = 0; int[] counts = new int[n * 2 + 1]; int prev = 0; for (int x : primes) { for (int y : primes) { if (y >= prev) { break; } counts[y + prev]++; } for (int i = x * 2 - 6; i >= 8; i -= 2) { if (!isNotPrime[i + x]) { ans += counts[i]; } } prev = x; } System.out.println(ans); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); 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 String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }