結果

問題 No.106 素数が嫌い!2
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-18 11:00:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 329 ms / 5,000 ms
コード長 1,071 bytes
コンパイル時間 2,727 ms
コンパイル使用メモリ 73,096 KB
実行使用メモリ 61,928 KB
最終ジャッジ日時 2023-09-17 22:35:17
合計ジャッジ時間 7,533 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 223 ms
60,128 KB
testcase_01 AC 128 ms
56,308 KB
testcase_02 AC 129 ms
56,072 KB
testcase_03 AC 128 ms
55,892 KB
testcase_04 AC 222 ms
60,020 KB
testcase_05 AC 324 ms
61,700 KB
testcase_06 AC 326 ms
61,928 KB
testcase_07 AC 328 ms
61,652 KB
testcase_08 AC 155 ms
58,032 KB
testcase_09 AC 154 ms
57,884 KB
testcase_10 AC 329 ms
61,896 KB
testcase_11 AC 212 ms
58,380 KB
testcase_12 AC 316 ms
61,916 KB
testcase_13 AC 128 ms
55,748 KB
testcase_14 AC 129 ms
55,884 KB
testcase_15 AC 130 ms
55,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
   public static void main(String[] args) throws Exception {
       Scanner koko = new Scanner(System.in);
       int num = koko.nextInt();
       int k = koko.nextInt();

       int ptr = 0;                        
       int[] prime = new int[200000];  

       prime[ptr++] = 2;
       prime[ptr++] = 3;           

       for (int n = 5; n <= num; n += 2) {  
           boolean wflag = false;
           for (int i = 0; prime[i]*prime[i] <= n; i++) { 
               if (n % prime[i] == 0){
                   wflag = true;
                   break;
               }
           }
           if (!wflag){
               prime[ptr++] = n;
           }                   
       }
       int number=0;
       int[] judge = new int[num+1];
       for(int i=0; i<ptr; i++){
           for(int j=1; j*prime[i]<=num; j++){
               judge[j*prime[i]]++;
           }
       }
       for(int i=2; i<num+1; i++){
           if(judge[i]>=k){
               number++;
           }
       }
       System.out.println(number);
   }
}
0