結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー htensaihtensai
提出日時 2020-02-03 16:39:07
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 778 bytes
コンパイル時間 3,344 ms
コンパイル使用メモリ 75,892 KB
実行使用メモリ 82,356 KB
最終ジャッジ日時 2023-10-19 04:19:04
合計ジャッジ時間 12,830 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
57,696 KB
testcase_01 AC 136 ms
57,264 KB
testcase_02 AC 136 ms
57,248 KB
testcase_03 AC 215 ms
58,160 KB
testcase_04 AC 137 ms
57,436 KB
testcase_05 AC 137 ms
57,496 KB
testcase_06 AC 140 ms
57,140 KB
testcase_07 AC 135 ms
57,628 KB
testcase_08 AC 135 ms
57,424 KB
testcase_09 AC 135 ms
57,204 KB
testcase_10 AC 137 ms
57,428 KB
testcase_11 AC 138 ms
57,416 KB
testcase_12 AC 139 ms
57,460 KB
testcase_13 AC 138 ms
57,168 KB
testcase_14 AC 150 ms
57,208 KB
testcase_15 AC 147 ms
57,148 KB
testcase_16 AC 143 ms
57,412 KB
testcase_17 AC 149 ms
57,436 KB
testcase_18 AC 139 ms
57,196 KB
testcase_19 AC 258 ms
60,692 KB
testcase_20 AC 465 ms
62,912 KB
testcase_21 AC 142 ms
57,492 KB
testcase_22 AC 146 ms
57,184 KB
testcase_23 AC 138 ms
57,496 KB
testcase_24 AC 140 ms
57,140 KB
testcase_25 AC 654 ms
67,320 KB
testcase_26 AC 135 ms
57,180 KB
testcase_27 AC 141 ms
57,504 KB
testcase_28 AC 133 ms
55,408 KB
testcase_29 AC 136 ms
57,208 KB
testcase_30 AC 136 ms
57,228 KB
testcase_31 AC 143 ms
57,284 KB
testcase_32 AC 383 ms
61,076 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 606 ms
67,184 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 = 0;
        TreeSet<Integer> primes = new TreeSet<>();
        for (int i = 2; i * (n - 1) <= m; i++) {
            if (isPrime(i, primes)) {
                primes.add(i);
                total += m - i * (n - 1) + 1;
            }
        }
        System.out.println(total);
    }
    
    static boolean isPrime(int x, TreeSet<Integer> primes) {
        for (int y : primes) {
            if (Math.sqrt(x) < y) {
                break;
            }
            if (x % y == 0) {
                return false;
            }
        }
        return true;
    }
}
0