結果

問題 No.106 素数が嫌い!2
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-04-09 16:04:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 190 ms / 5,000 ms
コード長 1,446 bytes
コンパイル時間 3,297 ms
コンパイル使用メモリ 74,556 KB
実行使用メモリ 64,452 KB
最終ジャッジ日時 2023-09-17 19:02:58
合計ジャッジ時間 6,861 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
59,700 KB
testcase_01 AC 125 ms
58,104 KB
testcase_02 AC 122 ms
55,700 KB
testcase_03 AC 125 ms
55,868 KB
testcase_04 AC 165 ms
59,424 KB
testcase_05 AC 184 ms
64,452 KB
testcase_06 AC 186 ms
63,916 KB
testcase_07 AC 186 ms
64,188 KB
testcase_08 AC 147 ms
55,748 KB
testcase_09 AC 148 ms
56,012 KB
testcase_10 AC 190 ms
63,580 KB
testcase_11 AC 165 ms
57,872 KB
testcase_12 AC 186 ms
64,348 KB
testcase_13 AC 125 ms
56,420 KB
testcase_14 AC 122 ms
55,732 KB
testcase_15 AC 125 ms
55,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//No.106 素数が嫌い!2

import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class No106 {
    
    static final Scanner in = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);

    static void solve() {
        int n = in.nextInt();
        int k = in.nextInt();
        boolean[] isPrime = sieveOfEratosthenes(n+1);
        int[] cnt = new int[n+1];
        int ans = 0;
        for (int i=2; i<=n; i++) {
            if (isPrime[i]) cnt[i]++;
            if (cnt[i] >= k) ans++;
            if (!isPrime[i]) continue;
            for (int j=i+i; j<=n; j+=i) {
                cnt[j]++;
            }
        }
        out.println(ans);
    }

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

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        solve();
        out.flush();

        long end = System.currentTimeMillis();
        //trace(end-start + "ms");
        in.close();
        out.close();
    }

    static void trace(Object... o) { System.out.println(deepToString(o));}
}
0