結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー htensaihtensai
提出日時 2020-02-03 17:24:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 187 ms / 1,000 ms
コード長 610 bytes
コンパイル時間 3,476 ms
コンパイル使用メモリ 78,600 KB
実行使用メモリ 61,564 KB
最終ジャッジ日時 2023-10-19 06:04:22
合計ジャッジ時間 8,359 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
57,576 KB
testcase_01 AC 134 ms
57,412 KB
testcase_02 AC 140 ms
57,432 KB
testcase_03 AC 143 ms
57,596 KB
testcase_04 AC 134 ms
57,420 KB
testcase_05 AC 135 ms
57,444 KB
testcase_06 AC 133 ms
57,152 KB
testcase_07 AC 133 ms
57,476 KB
testcase_08 AC 136 ms
57,388 KB
testcase_09 AC 134 ms
57,452 KB
testcase_10 AC 137 ms
57,412 KB
testcase_11 AC 135 ms
57,408 KB
testcase_12 AC 134 ms
57,476 KB
testcase_13 AC 133 ms
57,116 KB
testcase_14 AC 132 ms
57,416 KB
testcase_15 AC 132 ms
57,384 KB
testcase_16 AC 132 ms
55,356 KB
testcase_17 AC 131 ms
57,376 KB
testcase_18 AC 131 ms
57,112 KB
testcase_19 AC 151 ms
57,196 KB
testcase_20 AC 152 ms
59,708 KB
testcase_21 AC 132 ms
57,512 KB
testcase_22 AC 136 ms
57,456 KB
testcase_23 AC 136 ms
57,420 KB
testcase_24 AC 135 ms
57,452 KB
testcase_25 AC 167 ms
59,696 KB
testcase_26 AC 135 ms
57,436 KB
testcase_27 AC 134 ms
57,620 KB
testcase_28 AC 135 ms
57,364 KB
testcase_29 AC 135 ms
57,376 KB
testcase_30 AC 135 ms
57,292 KB
testcase_31 AC 130 ms
57,596 KB
testcase_32 AC 158 ms
59,436 KB
testcase_33 AC 182 ms
61,564 KB
testcase_34 AC 187 ms
61,552 KB
testcase_35 AC 160 ms
59,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[]  args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int length = m / (n - 1) + 1;
        boolean[] isPrime = new boolean[length];
        long total = 0;
        for (int i = 2; i * (n - 1) <= m; i++) {
            if (!isPrime[i]) {
                total += m - i * (n - 1) + 1;
                for (int j = i * 2; j < length; j += i) {
                    isPrime[j] = true;
                }
            }
        }
        System.out.println(total);
    }
}
0