結果

問題 No.106 素数が嫌い!2
ユーザー rf141rf141
提出日時 2015-08-13 09:10:42
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,274 bytes
コンパイル時間 3,671 ms
コンパイル使用メモリ 75,124 KB
実行使用メモリ 92,668 KB
最終ジャッジ日時 2023-09-25 11:25:16
合計ジャッジ時間 16,250 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class HatePrenum{

	protected List<Integer> prenumList;

	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		HatePrenum hate = new HatePrenum();
		int N = scan.nextInt();
		int K = scan.nextInt();
		int[] d = new int[N+1];
		hate.makePrenumList(N);
		int res=0;
		if(K==1){
			System.out.println(hate.prenumList.size());
			return;
		}else{
			for(int i = 2; i <= N; i++){
				if(d[i] == 0){
					for(int j = 1; i*j<=N; j++){
						d[i*j]++;
					}
				}
			}
			for(int i = 2; i <= N; i++){
				if(d[i]>=K)res++;
			}
			System.out.println(res);
		}
	}
	public void makePrenumList(int max){
		List<Integer> searchList = new ArrayList<Integer>();
		List<Integer> prenum = new ArrayList<Integer>();
		double limit = Math.sqrt(max);
		for(int i = 2; i <= max; i++){
			searchList.add(i);
		}
		double head = 0.0;
		int nowHead;	
		while(head < limit){
			head = (double)searchList.get(0);
			nowHead = (int)head;
			prenum.add(nowHead);
			for(Iterator<Integer> it = searchList.iterator(); it.hasNext();){
				int num = it.next();
				if(num%nowHead==0){
					it.remove();
				}
			}
		}
		for(Iterator<Integer> it = searchList.iterator(); it.hasNext();){
			prenum.add(it.next());
		}
		this.prenumList=prenum;
	}
}
0