結果
| 問題 |
No.106 素数が嫌い!2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-08-13 09:10:42 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,274 bytes |
| コンパイル時間 | 3,231 ms |
| コンパイル使用メモリ | 78,468 KB |
| 実行使用メモリ | 97,652 KB |
| 最終ジャッジ日時 | 2024-07-18 09:13:16 |
| 合計ジャッジ時間 | 15,946 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 12 |
ソースコード
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;
}
}