結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー YamaKasaYamaKasa
提出日時 2018-09-19 17:48:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 171 ms / 1,000 ms
コード長 768 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 73,560 KB
実行使用メモリ 59,848 KB
最終ジャッジ日時 2023-09-25 10:14:26
合計ジャッジ時間 8,551 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,872 KB
testcase_01 AC 120 ms
55,848 KB
testcase_02 AC 120 ms
55,732 KB
testcase_03 AC 140 ms
56,284 KB
testcase_04 AC 122 ms
55,912 KB
testcase_05 AC 122 ms
55,684 KB
testcase_06 AC 121 ms
55,940 KB
testcase_07 AC 121 ms
55,452 KB
testcase_08 AC 121 ms
55,748 KB
testcase_09 AC 119 ms
55,448 KB
testcase_10 AC 123 ms
56,620 KB
testcase_11 AC 119 ms
55,620 KB
testcase_12 AC 119 ms
55,772 KB
testcase_13 AC 123 ms
56,084 KB
testcase_14 AC 122 ms
56,000 KB
testcase_15 AC 118 ms
55,716 KB
testcase_16 AC 119 ms
55,860 KB
testcase_17 AC 121 ms
55,476 KB
testcase_18 AC 122 ms
55,608 KB
testcase_19 AC 139 ms
55,852 KB
testcase_20 AC 152 ms
58,012 KB
testcase_21 AC 118 ms
55,964 KB
testcase_22 AC 119 ms
55,852 KB
testcase_23 AC 121 ms
55,468 KB
testcase_24 AC 121 ms
56,068 KB
testcase_25 AC 153 ms
57,516 KB
testcase_26 AC 121 ms
55,772 KB
testcase_27 AC 131 ms
55,924 KB
testcase_28 AC 119 ms
55,764 KB
testcase_29 AC 121 ms
55,632 KB
testcase_30 AC 122 ms
55,876 KB
testcase_31 AC 122 ms
55,608 KB
testcase_32 AC 146 ms
58,068 KB
testcase_33 AC 171 ms
59,800 KB
testcase_34 AC 169 ms
59,848 KB
testcase_35 AC 151 ms
57,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static boolean[] isPrime;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int L = scan.nextInt();
		scan.close();
		int max = L / (N -1);
		isPrime = new boolean[max + 1];
		long cnt = 0;
		if(max >= 2) {
			aryPrime();
		}

		for(int i = 2; i < max + 1; i++) {
			if(isPrime[i]) {
				cnt += L - (N - 1) * i + 1;
			}
		}
		System.out.println(cnt);
	}
	static void aryPrime(){
		int l = isPrime.length;
		for(int i = 0; i < l; i++) {
			isPrime[i] = true;
		}
		isPrime[0] = false;
		isPrime[1] = false;
		for(int i = 2; i <= (int)Math.sqrt(l); i++) {
			if(isPrime[i]) {
				for(int j = i * 2; j < l; j += i) {
					isPrime[j] = false;
				}
			}
		}
	}
}
0