結果

問題 No.732 3PrimeCounting
ユーザー tentententen
提出日時 2023-04-10 17:08:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 584 ms / 3,000 ms
コード長 2,348 bytes
コンパイル時間 2,595 ms
コンパイル使用メモリ 93,528 KB
実行使用メモリ 45,244 KB
最終ジャッジ日時 2024-04-15 21:41:18
合計ジャッジ時間 16,524 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
37,300 KB
testcase_01 AC 48 ms
37,056 KB
testcase_02 AC 50 ms
36,928 KB
testcase_03 AC 50 ms
36,964 KB
testcase_04 AC 49 ms
37,240 KB
testcase_05 AC 49 ms
37,320 KB
testcase_06 AC 48 ms
37,400 KB
testcase_07 AC 49 ms
37,144 KB
testcase_08 AC 49 ms
37,272 KB
testcase_09 AC 50 ms
37,068 KB
testcase_10 AC 49 ms
37,448 KB
testcase_11 AC 49 ms
36,756 KB
testcase_12 AC 50 ms
36,932 KB
testcase_13 AC 48 ms
37,244 KB
testcase_14 AC 50 ms
37,440 KB
testcase_15 AC 47 ms
37,400 KB
testcase_16 AC 48 ms
36,752 KB
testcase_17 AC 48 ms
37,020 KB
testcase_18 AC 47 ms
36,904 KB
testcase_19 AC 48 ms
36,928 KB
testcase_20 AC 57 ms
37,080 KB
testcase_21 AC 75 ms
38,120 KB
testcase_22 AC 87 ms
38,392 KB
testcase_23 AC 52 ms
37,152 KB
testcase_24 AC 51 ms
37,012 KB
testcase_25 AC 99 ms
39,732 KB
testcase_26 AC 97 ms
38,960 KB
testcase_27 AC 62 ms
37,664 KB
testcase_28 AC 72 ms
37,364 KB
testcase_29 AC 87 ms
38,704 KB
testcase_30 AC 84 ms
38,676 KB
testcase_31 AC 91 ms
38,812 KB
testcase_32 AC 95 ms
39,716 KB
testcase_33 AC 102 ms
39,656 KB
testcase_34 AC 101 ms
38,832 KB
testcase_35 AC 98 ms
39,492 KB
testcase_36 AC 97 ms
39,144 KB
testcase_37 AC 53 ms
37,040 KB
testcase_38 AC 54 ms
37,448 KB
testcase_39 AC 98 ms
39,004 KB
testcase_40 AC 94 ms
38,992 KB
testcase_41 AC 92 ms
39,160 KB
testcase_42 AC 90 ms
39,016 KB
testcase_43 AC 90 ms
38,852 KB
testcase_44 AC 71 ms
38,168 KB
testcase_45 AC 65 ms
37,928 KB
testcase_46 AC 66 ms
37,908 KB
testcase_47 AC 72 ms
38,220 KB
testcase_48 AC 98 ms
39,488 KB
testcase_49 AC 97 ms
39,672 KB
testcase_50 AC 74 ms
38,524 KB
testcase_51 AC 75 ms
38,644 KB
testcase_52 AC 64 ms
37,716 KB
testcase_53 AC 106 ms
39,928 KB
testcase_54 AC 262 ms
40,960 KB
testcase_55 AC 317 ms
43,152 KB
testcase_56 AC 252 ms
43,216 KB
testcase_57 AC 127 ms
40,000 KB
testcase_58 AC 145 ms
40,432 KB
testcase_59 AC 126 ms
39,872 KB
testcase_60 AC 140 ms
40,324 KB
testcase_61 AC 142 ms
40,240 KB
testcase_62 AC 239 ms
41,084 KB
testcase_63 AC 164 ms
40,764 KB
testcase_64 AC 177 ms
40,212 KB
testcase_65 AC 146 ms
40,436 KB
testcase_66 AC 51 ms
37,332 KB
testcase_67 AC 50 ms
37,076 KB
testcase_68 AC 283 ms
40,696 KB
testcase_69 AC 249 ms
41,100 KB
testcase_70 AC 252 ms
40,816 KB
testcase_71 AC 186 ms
40,460 KB
testcase_72 AC 140 ms
40,456 KB
testcase_73 AC 324 ms
41,452 KB
testcase_74 AC 454 ms
41,592 KB
testcase_75 AC 100 ms
39,656 KB
testcase_76 AC 224 ms
41,064 KB
testcase_77 AC 131 ms
40,160 KB
testcase_78 AC 272 ms
41,052 KB
testcase_79 AC 294 ms
40,772 KB
testcase_80 AC 301 ms
43,024 KB
testcase_81 AC 272 ms
40,732 KB
testcase_82 AC 58 ms
37,408 KB
testcase_83 AC 127 ms
40,080 KB
testcase_84 AC 148 ms
40,276 KB
testcase_85 AC 246 ms
40,768 KB
testcase_86 AC 268 ms
45,244 KB
testcase_87 AC 379 ms
41,760 KB
testcase_88 AC 584 ms
41,236 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 < 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 * 2];
        long ans = 0;
        for (int i = 2; i < primes.size(); i++) {
            if (primes.get(i) > n) {
                break;
            }
            for (int j = 0; j < i - 1; j++) {
                counts[primes.get(j) + primes.get(i - 1)]++;
            }
            for (int j = i + 1; j < primes.size() && primes.get(j) < primes.get(i) * 3; 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();
    }
    
}
0