結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー htensaihtensai
提出日時 2020-02-03 17:12:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 880 ms / 1,000 ms
コード長 784 bytes
コンパイル時間 2,210 ms
コンパイル使用メモリ 75,464 KB
実行使用メモリ 64,520 KB
最終ジャッジ日時 2023-10-19 05:37:08
合計ジャッジ時間 11,380 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
57,392 KB
testcase_01 AC 136 ms
55,268 KB
testcase_02 AC 143 ms
57,548 KB
testcase_03 AC 179 ms
57,580 KB
testcase_04 AC 136 ms
57,540 KB
testcase_05 AC 140 ms
57,068 KB
testcase_06 AC 137 ms
57,404 KB
testcase_07 AC 139 ms
57,348 KB
testcase_08 AC 137 ms
55,396 KB
testcase_09 AC 137 ms
55,256 KB
testcase_10 AC 137 ms
57,352 KB
testcase_11 AC 140 ms
57,472 KB
testcase_12 AC 137 ms
57,488 KB
testcase_13 AC 139 ms
57,296 KB
testcase_14 AC 141 ms
57,100 KB
testcase_15 AC 137 ms
57,324 KB
testcase_16 AC 140 ms
57,276 KB
testcase_17 AC 139 ms
57,316 KB
testcase_18 AC 139 ms
57,364 KB
testcase_19 AC 209 ms
59,476 KB
testcase_20 AC 320 ms
62,008 KB
testcase_21 AC 136 ms
57,352 KB
testcase_22 AC 136 ms
57,440 KB
testcase_23 AC 135 ms
57,428 KB
testcase_24 AC 137 ms
57,444 KB
testcase_25 AC 464 ms
61,892 KB
testcase_26 AC 138 ms
57,324 KB
testcase_27 AC 140 ms
57,308 KB
testcase_28 AC 139 ms
57,024 KB
testcase_29 AC 136 ms
57,400 KB
testcase_30 AC 136 ms
57,356 KB
testcase_31 AC 140 ms
57,320 KB
testcase_32 AC 283 ms
59,516 KB
testcase_33 AC 880 ms
64,348 KB
testcase_34 AC 879 ms
64,520 KB
testcase_35 AC 422 ms
62,084 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;
        ArrayList<Integer> primes = new ArrayList<>();
        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, ArrayList<Integer> primes) {
        for (int y : primes) {
            if (Math.sqrt(x) < y) {
                break;
            }
            if (x % y == 0) {
                return false;
            }
        }
        return true;
    }
}
0