結果
問題 | No.732 3PrimeCounting |
ユーザー | tenten |
提出日時 | 2021-11-11 18:08:22 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,874 ms / 3,000 ms |
コード長 | 1,901 bytes |
コンパイル時間 | 3,482 ms |
コンパイル使用メモリ | 78,464 KB |
実行使用メモリ | 43,328 KB |
最終ジャッジ日時 | 2024-11-23 03:12:53 |
合計ジャッジ時間 | 27,088 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
36,836 KB |
testcase_01 | AC | 53 ms
37,092 KB |
testcase_02 | AC | 53 ms
36,576 KB |
testcase_03 | AC | 53 ms
37,112 KB |
testcase_04 | AC | 52 ms
36,856 KB |
testcase_05 | AC | 52 ms
37,204 KB |
testcase_06 | AC | 53 ms
36,712 KB |
testcase_07 | AC | 52 ms
36,568 KB |
testcase_08 | AC | 53 ms
36,844 KB |
testcase_09 | AC | 53 ms
36,884 KB |
testcase_10 | AC | 54 ms
36,712 KB |
testcase_11 | AC | 52 ms
36,864 KB |
testcase_12 | AC | 52 ms
36,900 KB |
testcase_13 | AC | 54 ms
36,860 KB |
testcase_14 | AC | 51 ms
37,252 KB |
testcase_15 | AC | 52 ms
36,716 KB |
testcase_16 | AC | 52 ms
37,132 KB |
testcase_17 | AC | 53 ms
37,040 KB |
testcase_18 | AC | 53 ms
36,864 KB |
testcase_19 | AC | 52 ms
37,128 KB |
testcase_20 | AC | 55 ms
37,028 KB |
testcase_21 | AC | 83 ms
37,848 KB |
testcase_22 | AC | 83 ms
38,360 KB |
testcase_23 | AC | 53 ms
37,176 KB |
testcase_24 | AC | 51 ms
36,972 KB |
testcase_25 | AC | 110 ms
39,612 KB |
testcase_26 | AC | 98 ms
39,352 KB |
testcase_27 | AC | 56 ms
37,176 KB |
testcase_28 | AC | 54 ms
37,120 KB |
testcase_29 | AC | 82 ms
38,072 KB |
testcase_30 | AC | 83 ms
37,996 KB |
testcase_31 | AC | 83 ms
38,028 KB |
testcase_32 | AC | 98 ms
39,448 KB |
testcase_33 | AC | 94 ms
39,448 KB |
testcase_34 | AC | 94 ms
39,148 KB |
testcase_35 | AC | 98 ms
38,912 KB |
testcase_36 | AC | 83 ms
39,016 KB |
testcase_37 | AC | 52 ms
37,224 KB |
testcase_38 | AC | 53 ms
36,972 KB |
testcase_39 | AC | 103 ms
39,536 KB |
testcase_40 | AC | 83 ms
38,968 KB |
testcase_41 | AC | 99 ms
38,888 KB |
testcase_42 | AC | 96 ms
38,764 KB |
testcase_43 | AC | 66 ms
38,444 KB |
testcase_44 | AC | 82 ms
38,336 KB |
testcase_45 | AC | 58 ms
37,100 KB |
testcase_46 | AC | 59 ms
37,096 KB |
testcase_47 | AC | 65 ms
37,180 KB |
testcase_48 | AC | 112 ms
39,176 KB |
testcase_49 | AC | 105 ms
38,992 KB |
testcase_50 | AC | 85 ms
38,500 KB |
testcase_51 | AC | 74 ms
38,120 KB |
testcase_52 | AC | 59 ms
37,096 KB |
testcase_53 | AC | 114 ms
39,556 KB |
testcase_54 | AC | 466 ms
40,064 KB |
testcase_55 | AC | 466 ms
40,172 KB |
testcase_56 | AC | 517 ms
39,780 KB |
testcase_57 | AC | 170 ms
39,656 KB |
testcase_58 | AC | 188 ms
42,108 KB |
testcase_59 | AC | 142 ms
40,176 KB |
testcase_60 | AC | 219 ms
42,096 KB |
testcase_61 | AC | 221 ms
42,172 KB |
testcase_62 | AC | 626 ms
40,388 KB |
testcase_63 | AC | 302 ms
40,344 KB |
testcase_64 | AC | 209 ms
39,784 KB |
testcase_65 | AC | 229 ms
39,656 KB |
testcase_66 | AC | 54 ms
37,272 KB |
testcase_67 | AC | 54 ms
36,880 KB |
testcase_68 | AC | 546 ms
40,660 KB |
testcase_69 | AC | 550 ms
40,392 KB |
testcase_70 | AC | 478 ms
42,948 KB |
testcase_71 | AC | 472 ms
39,720 KB |
testcase_72 | AC | 317 ms
42,436 KB |
testcase_73 | AC | 1,100 ms
42,956 KB |
testcase_74 | AC | 957 ms
40,376 KB |
testcase_75 | AC | 114 ms
39,368 KB |
testcase_76 | AC | 572 ms
40,520 KB |
testcase_77 | AC | 197 ms
42,304 KB |
testcase_78 | AC | 763 ms
40,804 KB |
testcase_79 | AC | 532 ms
42,612 KB |
testcase_80 | AC | 674 ms
40,276 KB |
testcase_81 | AC | 483 ms
40,076 KB |
testcase_82 | AC | 54 ms
37,172 KB |
testcase_83 | AC | 189 ms
42,032 KB |
testcase_84 | AC | 203 ms
42,452 KB |
testcase_85 | AC | 416 ms
40,128 KB |
testcase_86 | AC | 725 ms
43,112 KB |
testcase_87 | AC | 1,838 ms
40,296 KB |
testcase_88 | AC | 1,874 ms
43,328 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(); } }