結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー TatsuDXTatsuDX
提出日時 2016-09-09 00:40:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 160 ms / 1,000 ms
コード長 672 bytes
コンパイル時間 3,585 ms
コンパイル使用メモリ 74,296 KB
実行使用メモリ 59,812 KB
最終ジャッジ日時 2023-08-22 06:20:18
合計ジャッジ時間 9,764 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,064 KB
testcase_01 AC 123 ms
55,968 KB
testcase_02 AC 121 ms
55,484 KB
testcase_03 AC 129 ms
55,472 KB
testcase_04 AC 122 ms
55,724 KB
testcase_05 AC 121 ms
55,744 KB
testcase_06 AC 124 ms
56,060 KB
testcase_07 AC 122 ms
56,100 KB
testcase_08 AC 123 ms
56,028 KB
testcase_09 AC 122 ms
56,256 KB
testcase_10 AC 123 ms
56,072 KB
testcase_11 AC 121 ms
56,044 KB
testcase_12 AC 123 ms
56,140 KB
testcase_13 AC 123 ms
56,048 KB
testcase_14 AC 122 ms
56,000 KB
testcase_15 AC 121 ms
55,680 KB
testcase_16 AC 120 ms
56,000 KB
testcase_17 AC 121 ms
56,188 KB
testcase_18 AC 120 ms
55,760 KB
testcase_19 AC 135 ms
56,040 KB
testcase_20 AC 141 ms
58,148 KB
testcase_21 AC 122 ms
55,672 KB
testcase_22 AC 120 ms
55,944 KB
testcase_23 AC 119 ms
55,760 KB
testcase_24 AC 119 ms
55,692 KB
testcase_25 AC 144 ms
58,056 KB
testcase_26 AC 119 ms
55,848 KB
testcase_27 AC 120 ms
55,856 KB
testcase_28 AC 124 ms
55,784 KB
testcase_29 AC 122 ms
56,108 KB
testcase_30 AC 122 ms
56,128 KB
testcase_31 AC 122 ms
56,396 KB
testcase_32 AC 139 ms
58,020 KB
testcase_33 AC 160 ms
59,812 KB
testcase_34 AC 158 ms
58,476 KB
testcase_35 AC 145 ms
57,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Test {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt(), m = sc.nextInt(), k = m - (n - 1) * 2, t;
		long sum = 0;
		if (k < 0) {
			System.out.println(0);
			return;
		}
		k = m / (n - 1);
		boolean[] b = new boolean[k + 1];
		b[0] = true;
		b[1] = true;
		t = 1;
		while ((t + 1) * (t + 1) <= k) {
			t++;
		}
		for (int i = 2; i <= t; i++) {
			if (b[i]) {
				continue;
			}
			for (int j = i * i; j <= k; j += i) {
				b[j] = true;
			}
		}
		for (int i = 2; i <= k; i++) {
			if (!b[i]) {
				sum += (long) (m - (n - 1) * i + 1);
			}
		}
		System.out.println(sum);
	}
}
0