結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー tentententen
提出日時 2020-09-11 18:44:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 176 ms / 1,000 ms
コード長 571 bytes
コンパイル時間 5,947 ms
コンパイル使用メモリ 77,656 KB
実行使用メモリ 60,340 KB
最終ジャッジ日時 2023-08-27 03:18:17
合計ジャッジ時間 8,225 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,008 KB
testcase_01 AC 121 ms
55,980 KB
testcase_02 AC 121 ms
55,756 KB
testcase_03 AC 131 ms
55,772 KB
testcase_04 AC 121 ms
56,104 KB
testcase_05 AC 121 ms
56,052 KB
testcase_06 AC 121 ms
56,136 KB
testcase_07 AC 121 ms
55,788 KB
testcase_08 AC 122 ms
55,908 KB
testcase_09 AC 122 ms
55,832 KB
testcase_10 AC 125 ms
56,280 KB
testcase_11 AC 121 ms
55,948 KB
testcase_12 AC 121 ms
56,164 KB
testcase_13 AC 122 ms
56,016 KB
testcase_14 AC 122 ms
55,932 KB
testcase_15 AC 121 ms
55,788 KB
testcase_16 AC 119 ms
55,940 KB
testcase_17 AC 120 ms
55,936 KB
testcase_18 AC 120 ms
56,088 KB
testcase_19 AC 132 ms
55,916 KB
testcase_20 AC 145 ms
57,844 KB
testcase_21 AC 124 ms
55,888 KB
testcase_22 AC 119 ms
55,788 KB
testcase_23 AC 123 ms
56,056 KB
testcase_24 AC 124 ms
54,440 KB
testcase_25 AC 151 ms
57,804 KB
testcase_26 AC 121 ms
55,780 KB
testcase_27 AC 123 ms
57,428 KB
testcase_28 AC 123 ms
55,736 KB
testcase_29 AC 121 ms
56,084 KB
testcase_30 AC 122 ms
55,508 KB
testcase_31 AC 124 ms
55,796 KB
testcase_32 AC 141 ms
57,852 KB
testcase_33 AC 176 ms
60,340 KB
testcase_34 AC 176 ms
59,780 KB
testcase_35 AC 148 ms
58,364 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 length = sc.nextInt();
    	boolean[] isNotPrime = new boolean[length / (n - 1) + 1];
    	long ans = 0;
    	for (int i = 2; i < isNotPrime.length; i++) {
    	    if (!isNotPrime[i]) {
    	        ans += length - i * (n - 1) + 1;
    	        for (int j = 2; j * i < isNotPrime.length; j++) {
    	            isNotPrime[i * j] = true;
    	        }
    	    }
    	}
        System.out.println(ans);
	}
}
0