結果
問題 | No.732 3PrimeCounting |
ユーザー | tenten |
提出日時 | 2023-01-31 14:58:09 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,639 bytes |
コンパイル時間 | 2,718 ms |
コンパイル使用メモリ | 95,992 KB |
実行使用メモリ | 57,756 KB |
最終ジャッジ日時 | 2024-06-30 17:57:34 |
合計ジャッジ時間 | 15,171 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
50,516 KB |
testcase_01 | AC | 51 ms
50,272 KB |
testcase_02 | AC | 50 ms
50,424 KB |
testcase_03 | AC | 50 ms
50,332 KB |
testcase_04 | AC | 50 ms
50,684 KB |
testcase_05 | AC | 50 ms
50,412 KB |
testcase_06 | AC | 50 ms
50,428 KB |
testcase_07 | AC | 50 ms
50,252 KB |
testcase_08 | AC | 49 ms
50,296 KB |
testcase_09 | AC | 50 ms
50,388 KB |
testcase_10 | AC | 50 ms
50,128 KB |
testcase_11 | AC | 51 ms
50,344 KB |
testcase_12 | AC | 52 ms
50,348 KB |
testcase_13 | AC | 50 ms
50,016 KB |
testcase_14 | AC | 51 ms
50,404 KB |
testcase_15 | AC | 49 ms
50,136 KB |
testcase_16 | AC | 51 ms
50,536 KB |
testcase_17 | AC | 49 ms
50,136 KB |
testcase_18 | AC | 51 ms
50,084 KB |
testcase_19 | AC | 52 ms
50,396 KB |
testcase_20 | AC | 93 ms
51,976 KB |
testcase_21 | AC | 165 ms
56,624 KB |
testcase_22 | AC | 164 ms
56,512 KB |
testcase_23 | AC | 60 ms
50,528 KB |
testcase_24 | AC | 60 ms
50,728 KB |
testcase_25 | AC | 231 ms
57,516 KB |
testcase_26 | AC | 213 ms
57,296 KB |
testcase_27 | AC | 111 ms
54,704 KB |
testcase_28 | AC | 110 ms
54,700 KB |
testcase_29 | AC | 152 ms
56,412 KB |
testcase_30 | AC | 150 ms
56,792 KB |
testcase_31 | AC | 181 ms
56,520 KB |
testcase_32 | AC | 247 ms
57,604 KB |
testcase_33 | AC | 246 ms
57,368 KB |
testcase_34 | AC | 227 ms
57,540 KB |
testcase_35 | AC | 193 ms
56,520 KB |
testcase_36 | AC | 202 ms
56,596 KB |
testcase_37 | AC | 84 ms
51,856 KB |
testcase_38 | AC | 84 ms
51,536 KB |
testcase_39 | AC | 208 ms
56,640 KB |
testcase_40 | AC | 190 ms
56,660 KB |
testcase_41 | AC | 188 ms
56,596 KB |
testcase_42 | AC | 191 ms
56,600 KB |
testcase_43 | AC | 163 ms
56,836 KB |
testcase_44 | AC | 156 ms
56,724 KB |
testcase_45 | AC | 116 ms
55,420 KB |
testcase_46 | AC | 116 ms
55,092 KB |
testcase_47 | AC | 129 ms
55,264 KB |
testcase_48 | AC | 243 ms
57,756 KB |
testcase_49 | AC | 239 ms
57,496 KB |
testcase_50 | AC | 173 ms
56,588 KB |
testcase_51 | AC | 162 ms
56,580 KB |
testcase_52 | AC | 115 ms
55,184 KB |
testcase_53 | AC | 406 ms
57,548 KB |
testcase_54 | TLE | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
testcase_60 | -- | - |
testcase_61 | -- | - |
testcase_62 | -- | - |
testcase_63 | -- | - |
testcase_64 | -- | - |
testcase_65 | -- | - |
testcase_66 | -- | - |
testcase_67 | -- | - |
testcase_68 | -- | - |
testcase_69 | -- | - |
testcase_70 | -- | - |
testcase_71 | -- | - |
testcase_72 | -- | - |
testcase_73 | -- | - |
testcase_74 | -- | - |
testcase_75 | -- | - |
testcase_76 | -- | - |
testcase_77 | -- | - |
testcase_78 | -- | - |
testcase_79 | -- | - |
testcase_80 | -- | - |
testcase_81 | -- | - |
testcase_82 | -- | - |
testcase_83 | -- | - |
testcase_84 | -- | - |
testcase_85 | -- | - |
testcase_86 | -- | - |
testcase_87 | -- | - |
testcase_88 | -- | - |
ソースコード
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; } } } HashMap<Integer, Integer> counts = new HashMap<>(); for (int i = 1; primes.get(i) <= n; i++) { int x = primes.get(i); for (int j = i + 1; j < primes.size(); j++) { int y = primes.get(j); counts.put(y - x, counts.getOrDefault(y - x, 0) + 1); } } long ans = 0; for (int i = 1; primes.get(i) <= n; i++) { int x = primes.get(i); for (int j = i + 1; j < primes.size(); j++) { int y = primes.get(j); counts.put(y - x, counts.get(y - x) - 1); } for (int j = 0; j < i; j++) { int y = primes.get(j); ans += counts.getOrDefault(x + y, 0); } } 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(); } }