結果

問題 No.106 素数が嫌い!2
ユーザー mitsuomitsuo
提出日時 2016-05-09 23:32:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 753 ms / 5,000 ms
コード長 971 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 77,940 KB
実行使用メモリ 49,404 KB
最終ジャッジ日時 2024-04-15 15:00:43
合計ジャッジ時間 9,326 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 373 ms
45,064 KB
testcase_01 AC 138 ms
41,504 KB
testcase_02 AC 137 ms
41,464 KB
testcase_03 AC 132 ms
41,496 KB
testcase_04 AC 370 ms
45,484 KB
testcase_05 AC 753 ms
49,404 KB
testcase_06 AC 749 ms
49,124 KB
testcase_07 AC 721 ms
49,256 KB
testcase_08 AC 158 ms
41,980 KB
testcase_09 AC 156 ms
41,820 KB
testcase_10 AC 717 ms
49,252 KB
testcase_11 AC 340 ms
44,940 KB
testcase_12 AC 703 ms
48,120 KB
testcase_13 AC 127 ms
41,516 KB
testcase_14 AC 131 ms
41,440 KB
testcase_15 AC 124 ms
41,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package jp.fedom.challange.yuki.l2.q106;

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<String> input = new ArrayList<>();
		while (sc.hasNext()) {
			input.add(sc.nextLine());
		}

		System.out.println(solve(input));

		sc.close();
	}

	public static int solve(List<String> in) {
		int N = Integer.valueOf(in.get(0).split(" ")[0]);
		int K = Integer.valueOf(in.get(0).split(" ")[1]);
		int[] f = new int[N + 1];

		int c = 0;

		for (int i = 2; i <= N; i++) {
			if (isPrime(i)) {
				for (int n = 1; i * n <= N; n++) {
					f[n * i]++;
					if (f[n * i] == K) {
						c++;
					}
				}
			}
		}

		return c;
	}

	private static boolean isPrime(int j) {
		int N = (int) Math.sqrt(j);
		boolean isPrime = true;
		for (int i = 2; i <= N; i++) {
			if (j % i == 0) {
				isPrime = false;
				break;
			}
		}
		return isPrime;
	}

}
0