結果

問題 No.106 素数が嫌い!2
ユーザー holegumaholeguma
提出日時 2015-08-19 23:42:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 940 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 73,936 KB
実行使用メモリ 60,540 KB
最終ジャッジ日時 2023-09-25 13:38:49
合計ジャッジ時間 4,467 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
57,016 KB
testcase_01 AC 44 ms
49,424 KB
testcase_02 AC 43 ms
49,812 KB
testcase_03 AC 43 ms
49,368 KB
testcase_04 AC 107 ms
56,444 KB
testcase_05 AC 123 ms
59,984 KB
testcase_06 AC 127 ms
60,540 KB
testcase_07 AC 124 ms
60,116 KB
testcase_08 AC 75 ms
52,108 KB
testcase_09 AC 75 ms
51,812 KB
testcase_10 AC 126 ms
59,944 KB
testcase_11 AC 104 ms
54,696 KB
testcase_12 AC 128 ms
60,088 KB
testcase_13 AC 45 ms
49,332 KB
testcase_14 AC 44 ms
49,428 KB
testcase_15 AC 44 ms
49,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main{

static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
StringTokenizer st=new StringTokenizer(line);
int n=Integer.parseInt(st.nextToken());
int k=Integer.parseInt(st.nextToken());
boolean[] p=sieveOfEratosthenes(n);
int[] a=new int[n+1];
for(int i=2;i<=n;i++){
if(p[i]) for(int j=i;j<=n;j+=i) a[j]++;
}
int ans=0;
for(int i=2;i<=n;i++) if(a[i]>=k) ans++;
out.println(ans);
}
out.flush();
}

public static boolean[] sieveOfEratosthenes(int n){
boolean[] p=new boolean[n+1];
Arrays.fill(p,true);
p[0]=false;
p[1]=false;
for(int i=2;i<=Math.sqrt(n);i++){
if(p[i]) for(int j=i+i;j<=n;j+=i) p[j]=false;
}
return p;
}
}
0