結果

問題 No.732 3PrimeCounting
ユーザー tentententen
提出日時 2023-05-08 12:54:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 937 ms / 3,000 ms
コード長 2,231 bytes
コンパイル時間 2,530 ms
コンパイル使用メモリ 97,880 KB
実行使用メモリ 43,064 KB
最終ジャッジ日時 2024-05-04 00:28:59
合計ジャッジ時間 20,043 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
36,688 KB
testcase_01 AC 49 ms
36,916 KB
testcase_02 AC 49 ms
37,044 KB
testcase_03 AC 50 ms
36,856 KB
testcase_04 AC 49 ms
36,660 KB
testcase_05 AC 48 ms
36,908 KB
testcase_06 AC 48 ms
37,068 KB
testcase_07 AC 49 ms
36,908 KB
testcase_08 AC 52 ms
36,796 KB
testcase_09 AC 49 ms
36,796 KB
testcase_10 AC 53 ms
36,884 KB
testcase_11 AC 52 ms
36,832 KB
testcase_12 AC 51 ms
37,120 KB
testcase_13 AC 50 ms
37,124 KB
testcase_14 AC 50 ms
37,064 KB
testcase_15 AC 51 ms
36,988 KB
testcase_16 AC 51 ms
36,512 KB
testcase_17 AC 53 ms
36,932 KB
testcase_18 AC 56 ms
36,656 KB
testcase_19 AC 53 ms
36,932 KB
testcase_20 AC 63 ms
36,948 KB
testcase_21 AC 95 ms
38,408 KB
testcase_22 AC 97 ms
38,700 KB
testcase_23 AC 52 ms
36,960 KB
testcase_24 AC 53 ms
36,952 KB
testcase_25 AC 110 ms
39,364 KB
testcase_26 AC 89 ms
38,840 KB
testcase_27 AC 68 ms
37,848 KB
testcase_28 AC 69 ms
37,680 KB
testcase_29 AC 69 ms
38,072 KB
testcase_30 AC 79 ms
38,116 KB
testcase_31 AC 92 ms
38,900 KB
testcase_32 AC 106 ms
39,460 KB
testcase_33 AC 91 ms
39,116 KB
testcase_34 AC 85 ms
38,928 KB
testcase_35 AC 94 ms
39,176 KB
testcase_36 AC 94 ms
38,956 KB
testcase_37 AC 53 ms
36,968 KB
testcase_38 AC 54 ms
36,656 KB
testcase_39 AC 87 ms
38,816 KB
testcase_40 AC 92 ms
38,572 KB
testcase_41 AC 95 ms
38,316 KB
testcase_42 AC 99 ms
38,492 KB
testcase_43 AC 94 ms
38,904 KB
testcase_44 AC 78 ms
37,960 KB
testcase_45 AC 76 ms
38,116 KB
testcase_46 AC 64 ms
37,844 KB
testcase_47 AC 69 ms
38,296 KB
testcase_48 AC 109 ms
39,252 KB
testcase_49 AC 104 ms
39,312 KB
testcase_50 AC 92 ms
38,540 KB
testcase_51 AC 92 ms
38,572 KB
testcase_52 AC 65 ms
37,876 KB
testcase_53 AC 94 ms
39,412 KB
testcase_54 AC 356 ms
42,708 KB
testcase_55 AC 393 ms
40,236 KB
testcase_56 AC 356 ms
42,764 KB
testcase_57 AC 133 ms
39,664 KB
testcase_58 AC 133 ms
39,504 KB
testcase_59 AC 102 ms
39,312 KB
testcase_60 AC 163 ms
39,552 KB
testcase_61 AC 157 ms
39,632 KB
testcase_62 AC 412 ms
40,380 KB
testcase_63 AC 218 ms
40,032 KB
testcase_64 AC 176 ms
40,064 KB
testcase_65 AC 174 ms
39,976 KB
testcase_66 AC 52 ms
37,240 KB
testcase_67 AC 51 ms
37,092 KB
testcase_68 AC 371 ms
43,064 KB
testcase_69 AC 388 ms
40,356 KB
testcase_70 AC 332 ms
40,380 KB
testcase_71 AC 360 ms
42,752 KB
testcase_72 AC 237 ms
39,932 KB
testcase_73 AC 688 ms
40,952 KB
testcase_74 AC 643 ms
41,292 KB
testcase_75 AC 94 ms
39,536 KB
testcase_76 AC 392 ms
40,584 KB
testcase_77 AC 140 ms
39,712 KB
testcase_78 AC 500 ms
40,524 KB
testcase_79 AC 358 ms
42,840 KB
testcase_80 AC 520 ms
43,020 KB
testcase_81 AC 366 ms
42,788 KB
testcase_82 AC 60 ms
37,488 KB
testcase_83 AC 135 ms
39,488 KB
testcase_84 AC 138 ms
39,636 KB
testcase_85 AC 326 ms
40,084 KB
testcase_86 AC 526 ms
40,660 KB
testcase_87 AC 879 ms
41,720 KB
testcase_88 AC 937 ms
41,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 < 3 * n; i++) {
            if (!isNotPrimes[i]) {
                primes.add(i);
                for (int j = 2; j * i < 3 * n; j++) {
                    isNotPrimes[j * i] = true;
                }
            }
        }
        int[] counts = new int[n * 3];
        long ans = 0;
        for (int i = 0; i < primes.size() && primes.get(i) <= n; i++) {
            for (int j = primes.size() - 1; j > i; j--) {
                ans += counts[primes.get(j) - primes.get(i)];
            }
            for (int j = 0; j < i; j++) {
                counts[primes.get(i) + primes.get(j)]++;
            }
        }
        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();
    }
    
}
0