結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー 37zigen37zigen
提出日時 2016-08-05 22:53:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 193 ms / 1,000 ms
コード長 864 bytes
コンパイル時間 2,205 ms
コンパイル使用メモリ 74,428 KB
実行使用メモリ 59,912 KB
最終ジャッジ日時 2023-08-22 03:44:07
合計ジャッジ時間 8,668 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,864 KB
testcase_01 AC 125 ms
55,556 KB
testcase_02 AC 125 ms
55,932 KB
testcase_03 AC 146 ms
55,976 KB
testcase_04 AC 125 ms
55,828 KB
testcase_05 AC 126 ms
56,204 KB
testcase_06 AC 127 ms
56,024 KB
testcase_07 AC 126 ms
56,052 KB
testcase_08 AC 126 ms
53,788 KB
testcase_09 AC 126 ms
55,772 KB
testcase_10 AC 126 ms
55,932 KB
testcase_11 AC 125 ms
54,052 KB
testcase_12 AC 125 ms
55,752 KB
testcase_13 AC 125 ms
55,772 KB
testcase_14 AC 125 ms
55,764 KB
testcase_15 AC 126 ms
55,556 KB
testcase_16 AC 127 ms
55,920 KB
testcase_17 AC 126 ms
55,608 KB
testcase_18 AC 127 ms
55,644 KB
testcase_19 AC 151 ms
55,764 KB
testcase_20 AC 159 ms
57,800 KB
testcase_21 AC 125 ms
56,028 KB
testcase_22 AC 127 ms
55,796 KB
testcase_23 AC 126 ms
54,112 KB
testcase_24 AC 126 ms
55,632 KB
testcase_25 AC 170 ms
57,940 KB
testcase_26 AC 126 ms
55,548 KB
testcase_27 AC 126 ms
55,636 KB
testcase_28 AC 124 ms
55,624 KB
testcase_29 AC 125 ms
55,712 KB
testcase_30 AC 125 ms
53,988 KB
testcase_31 AC 126 ms
56,016 KB
testcase_32 AC 157 ms
58,036 KB
testcase_33 AC 193 ms
59,516 KB
testcase_34 AC 193 ms
59,912 KB
testcase_35 AC 166 ms
57,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solver();
	}

	static void solver() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		if(l/(n-1)>=2){
			boolean[] isPrime = isPrimeArray(l / (n - 1));
			long ans = 0;
			for (int i = 2; i <= l / (n - 1); i++) {
				if (isPrime[i]) {
					ans += l - (n - 1) * i + 1;
				}
			}
			System.out.println(ans);

		}else{
			System.out.println(0);
			return;
		}

	}

	static int count = 0;

	static boolean[] isPrimeArray(int max) {
		boolean[] isPrime = new boolean[max + 1];
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for (int i = 2; i * i <= max; i++) {
			if (isPrime[i]) {
				for (int j = 2; j * i <= max; j++) {
					isPrime[j * i] = false;
				}
			}
		}
		return isPrime;
	}
}
0