結果

問題 No.826 連絡網
ユーザー ks2mks2m
提出日時 2019-05-03 22:00:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 1,017 bytes
コンパイル時間 3,397 ms
コンパイル使用メモリ 78,668 KB
実行使用メモリ 61,140 KB
最終ジャッジ日時 2023-08-15 18:17:50
合計ジャッジ時間 11,044 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,728 KB
testcase_01 AC 129 ms
57,840 KB
testcase_02 AC 130 ms
55,796 KB
testcase_03 AC 134 ms
55,668 KB
testcase_04 AC 135 ms
56,320 KB
testcase_05 AC 131 ms
55,888 KB
testcase_06 AC 132 ms
55,904 KB
testcase_07 AC 134 ms
55,792 KB
testcase_08 AC 135 ms
55,840 KB
testcase_09 AC 137 ms
56,036 KB
testcase_10 AC 127 ms
56,252 KB
testcase_11 AC 130 ms
56,084 KB
testcase_12 AC 283 ms
60,744 KB
testcase_13 AC 196 ms
58,224 KB
testcase_14 AC 232 ms
58,312 KB
testcase_15 AC 150 ms
58,000 KB
testcase_16 AC 209 ms
58,268 KB
testcase_17 AC 198 ms
58,208 KB
testcase_18 AC 190 ms
58,240 KB
testcase_19 AC 302 ms
60,384 KB
testcase_20 AC 296 ms
58,652 KB
testcase_21 AC 137 ms
55,708 KB
testcase_22 AC 206 ms
58,144 KB
testcase_23 AC 212 ms
57,936 KB
testcase_24 AC 185 ms
58,228 KB
testcase_25 AC 331 ms
60,356 KB
testcase_26 AC 194 ms
58,124 KB
testcase_27 AC 285 ms
60,144 KB
testcase_28 AC 243 ms
58,620 KB
testcase_29 AC 199 ms
57,904 KB
testcase_30 AC 327 ms
61,140 KB
testcase_31 AC 206 ms
58,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p= sc.nextInt();
		sc.close();

		if (p == 1) {
			System.out.println(1);
			return;
		}

		List<Integer> sosuu = sosuuList(n);
		Set<Integer> set = new HashSet<Integer>();
		int n2 = n / 2;
		for (Integer o : sosuu) {
			if (o > n2) {
				set.add(o);
			}
		}

		if (set.contains(p)) {
			System.out.println(1);
		} else {
			System.out.println(n - set.size() - 1);
		}
	}

	static List<Integer> sosuuList(int n) {
		List<Integer> sosuu = new ArrayList<Integer>();
		for (int i = 2; i <= n; i++) {
			int r = (int) Math.sqrt(i);
			boolean flg = false;
			for (Integer o : sosuu) {
				if (r < o) {
					break;
				}
				if (i % o == 0) {
					flg = true;
					break;
				}
			}
			if (!flg) {
				sosuu.add(i);
			}
		}
		return sosuu;
	}
}
0