結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー htensaihtensai
提出日時 2020-02-03 17:23:10
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 664 bytes
コンパイル時間 2,271 ms
コンパイル使用メモリ 74,560 KB
実行使用メモリ 61,740 KB
最終ジャッジ日時 2023-10-19 06:00:46
合計ジャッジ時間 8,562 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
57,352 KB
testcase_01 AC 132 ms
57,356 KB
testcase_02 RE -
testcase_03 AC 144 ms
57,604 KB
testcase_04 AC 135 ms
57,384 KB
testcase_05 AC 134 ms
57,312 KB
testcase_06 AC 135 ms
57,372 KB
testcase_07 AC 135 ms
57,344 KB
testcase_08 AC 135 ms
57,336 KB
testcase_09 AC 134 ms
57,348 KB
testcase_10 AC 134 ms
57,404 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 136 ms
57,416 KB
testcase_14 AC 131 ms
57,344 KB
testcase_15 RE -
testcase_16 AC 133 ms
57,324 KB
testcase_17 AC 136 ms
57,384 KB
testcase_18 AC 136 ms
57,400 KB
testcase_19 AC 146 ms
57,384 KB
testcase_20 AC 154 ms
59,456 KB
testcase_21 AC 134 ms
57,556 KB
testcase_22 AC 133 ms
57,368 KB
testcase_23 AC 135 ms
57,424 KB
testcase_24 AC 134 ms
57,380 KB
testcase_25 AC 165 ms
59,416 KB
testcase_26 AC 131 ms
57,304 KB
testcase_27 RE -
testcase_28 AC 132 ms
55,616 KB
testcase_29 AC 133 ms
57,400 KB
testcase_30 AC 135 ms
57,560 KB
testcase_31 AC 135 ms
55,336 KB
testcase_32 AC 154 ms
59,560 KB
testcase_33 AC 183 ms
61,740 KB
testcase_34 AC 183 ms
61,680 KB
testcase_35 AC 161 ms
59,208 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];
        isPrime[0] = true;
        isPrime[1] = true;
        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