結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー htensaihtensai
提出日時 2020-02-03 17:15:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 819 ms / 1,000 ms
コード長 841 bytes
コンパイル時間 2,163 ms
コンパイル使用メモリ 75,924 KB
実行使用メモリ 64,392 KB
最終ジャッジ日時 2023-10-19 05:41:50
合計ジャッジ時間 10,709 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
57,212 KB
testcase_01 AC 135 ms
57,484 KB
testcase_02 AC 135 ms
57,236 KB
testcase_03 AC 159 ms
57,552 KB
testcase_04 AC 133 ms
57,224 KB
testcase_05 AC 133 ms
57,348 KB
testcase_06 AC 132 ms
57,344 KB
testcase_07 AC 136 ms
57,356 KB
testcase_08 AC 133 ms
57,076 KB
testcase_09 AC 133 ms
57,256 KB
testcase_10 AC 131 ms
57,196 KB
testcase_11 AC 132 ms
57,224 KB
testcase_12 AC 132 ms
57,328 KB
testcase_13 AC 135 ms
57,184 KB
testcase_14 AC 134 ms
57,476 KB
testcase_15 AC 133 ms
57,352 KB
testcase_16 AC 135 ms
57,252 KB
testcase_17 AC 135 ms
57,192 KB
testcase_18 AC 130 ms
56,924 KB
testcase_19 AC 195 ms
59,632 KB
testcase_20 AC 313 ms
62,080 KB
testcase_21 AC 132 ms
57,300 KB
testcase_22 AC 130 ms
57,040 KB
testcase_23 AC 132 ms
57,236 KB
testcase_24 AC 133 ms
57,248 KB
testcase_25 AC 434 ms
62,188 KB
testcase_26 AC 132 ms
57,180 KB
testcase_27 AC 131 ms
57,212 KB
testcase_28 AC 135 ms
57,196 KB
testcase_29 AC 135 ms
55,308 KB
testcase_30 AC 133 ms
57,336 KB
testcase_31 AC 132 ms
57,336 KB
testcase_32 AC 269 ms
59,736 KB
testcase_33 AC 819 ms
64,308 KB
testcase_34 AC 819 ms
64,392 KB
testcase_35 AC 400 ms
61,816 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();
        long total = Math.max(m - 2 * (n - 1) + 1, 0);
        ArrayList<Integer> primes = new ArrayList<>();
        primes.add(2);
        for (int i = 3; i * (n - 1) <= m; i += 2) {
            if (isPrime(i, primes)) {
                primes.add(i);
                total += m - i * (n - 1) + 1;
            }
        }
        System.out.println(total);
    }
    
    static boolean isPrime(int x, ArrayList<Integer> primes) {
        for (int y : primes) {
            if (Math.sqrt(x) < y) {
                break;
            }
            if (x % y == 0) {
                return false;
            }
        }
        return true;
    }
}
0