結果

問題 No.732 3PrimeCounting
ユーザー tentententen
提出日時 2020-10-28 10:23:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 488 ms / 3,000 ms
コード長 1,172 bytes
コンパイル時間 4,324 ms
コンパイル使用メモリ 74,720 KB
実行使用メモリ 58,504 KB
最終ジャッジ日時 2023-09-29 03:36:15
合計ジャッジ時間 25,603 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,728 KB
testcase_01 AC 127 ms
55,808 KB
testcase_02 AC 128 ms
55,828 KB
testcase_03 AC 126 ms
55,764 KB
testcase_04 AC 125 ms
55,796 KB
testcase_05 AC 126 ms
55,460 KB
testcase_06 AC 126 ms
55,588 KB
testcase_07 AC 129 ms
55,776 KB
testcase_08 AC 128 ms
55,944 KB
testcase_09 AC 129 ms
55,772 KB
testcase_10 AC 130 ms
53,764 KB
testcase_11 AC 129 ms
55,512 KB
testcase_12 AC 128 ms
55,524 KB
testcase_13 AC 128 ms
55,840 KB
testcase_14 AC 128 ms
55,720 KB
testcase_15 AC 129 ms
55,692 KB
testcase_16 AC 126 ms
55,676 KB
testcase_17 AC 128 ms
55,636 KB
testcase_18 AC 123 ms
55,676 KB
testcase_19 AC 126 ms
55,428 KB
testcase_20 AC 133 ms
56,000 KB
testcase_21 AC 176 ms
56,196 KB
testcase_22 AC 177 ms
56,156 KB
testcase_23 AC 130 ms
55,808 KB
testcase_24 AC 130 ms
55,676 KB
testcase_25 AC 173 ms
58,308 KB
testcase_26 AC 184 ms
56,072 KB
testcase_27 AC 134 ms
55,756 KB
testcase_28 AC 135 ms
56,180 KB
testcase_29 AC 163 ms
56,144 KB
testcase_30 AC 161 ms
56,104 KB
testcase_31 AC 179 ms
56,268 KB
testcase_32 AC 156 ms
56,084 KB
testcase_33 AC 158 ms
56,380 KB
testcase_34 AC 158 ms
55,852 KB
testcase_35 AC 181 ms
56,632 KB
testcase_36 AC 179 ms
56,680 KB
testcase_37 AC 132 ms
55,840 KB
testcase_38 AC 131 ms
55,572 KB
testcase_39 AC 178 ms
56,628 KB
testcase_40 AC 190 ms
56,552 KB
testcase_41 AC 188 ms
56,436 KB
testcase_42 AC 183 ms
56,268 KB
testcase_43 AC 180 ms
56,812 KB
testcase_44 AC 180 ms
56,556 KB
testcase_45 AC 134 ms
55,848 KB
testcase_46 AC 135 ms
53,792 KB
testcase_47 AC 143 ms
53,788 KB
testcase_48 AC 156 ms
56,420 KB
testcase_49 AC 155 ms
55,960 KB
testcase_50 AC 181 ms
56,480 KB
testcase_51 AC 164 ms
56,248 KB
testcase_52 AC 136 ms
55,936 KB
testcase_53 AC 163 ms
56,164 KB
testcase_54 AC 275 ms
58,240 KB
testcase_55 AC 274 ms
58,264 KB
testcase_56 AC 273 ms
58,040 KB
testcase_57 AC 190 ms
56,296 KB
testcase_58 AC 191 ms
56,168 KB
testcase_59 AC 188 ms
55,972 KB
testcase_60 AC 207 ms
56,176 KB
testcase_61 AC 203 ms
56,160 KB
testcase_62 AC 311 ms
58,228 KB
testcase_63 AC 233 ms
56,000 KB
testcase_64 AC 230 ms
56,268 KB
testcase_65 AC 212 ms
56,356 KB
testcase_66 AC 129 ms
55,916 KB
testcase_67 AC 130 ms
55,988 KB
testcase_68 AC 293 ms
57,952 KB
testcase_69 AC 292 ms
58,356 KB
testcase_70 AC 279 ms
57,976 KB
testcase_71 AC 283 ms
58,504 KB
testcase_72 AC 225 ms
55,992 KB
testcase_73 AC 400 ms
58,232 KB
testcase_74 AC 401 ms
58,224 KB
testcase_75 AC 177 ms
56,520 KB
testcase_76 AC 287 ms
58,032 KB
testcase_77 AC 213 ms
56,264 KB
testcase_78 AC 352 ms
58,036 KB
testcase_79 AC 289 ms
57,780 KB
testcase_80 AC 332 ms
58,032 KB
testcase_81 AC 277 ms
58,184 KB
testcase_82 AC 136 ms
55,836 KB
testcase_83 AC 195 ms
55,900 KB
testcase_84 AC 199 ms
56,256 KB
testcase_85 AC 263 ms
58,420 KB
testcase_86 AC 334 ms
56,140 KB
testcase_87 AC 488 ms
58,172 KB
testcase_88 AC 486 ms
58,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean[] isNotPrime = new boolean[n * 3];
        for (int i = 2; i <= Math.sqrt(n * 3); i++) {
            if (!isNotPrime[i]) {
                for (int j = 2; i * j < n * 3; j++) {
                    isNotPrime[i * j] = true;
                }
            }
        }
        ArrayList<Integer> primes = new ArrayList<>();
        for (int i = 3; i < n * 3; i++) {
            if (!isNotPrime[i]) {
                primes.add(i);
            }
        }
        int[] counts = new int[n * 3];
        counts[8]++;
        int max = 8;
        long ans = 0;
        for (int i = 2; primes.get(i) <= n; i++) {
            for (int j = i + 1; j < primes.size() && primes.get(j) - primes.get(i) <= max; j++) {
                ans += counts[primes.get(j) - primes.get(i)];
            }
            for (int j = 0; j < i; j++) {
                counts[primes.get(i) + primes.get(j)]++;
            }
            max = primes.get(i) + primes.get(i - 1);
        }
        System.out.println(ans);
    }
}
0