結果

問題 No.106 素数が嫌い!2
ユーザー ぴろずぴろず
提出日時 2014-12-18 23:27:52
言語 Java
(openjdk 23)
結果
AC  
実行時間 152 ms / 5,000 ms
コード長 544 bytes
コンパイル時間 2,414 ms
コンパイル使用メモリ 74,264 KB
実行使用メモリ 49,216 KB
最終ジャッジ日時 2024-06-12 01:19:05
合計ジャッジ時間 4,964 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

package no106;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		if (k == 1) {
			System.out.println(n - 1);
			return;
		}
		int[] factors = new int[n+1];
		for(int i=2;i<=n;i++) {
			if (factors[i] == 0) {
				int x = i * 2;
				while(x <= n) {
					factors[x]++;
					x += i;
				}
			}
		}
		int ans = 0;
		for(int i=2;i<=n;i++) {
			if (factors[i] >= k) {
				ans++;
			}
		}
		System.out.println(ans);
	}

}
0