結果

問題 No.106 素数が嫌い!2
ユーザー phsplsphspls
提出日時 2020-06-03 15:47:49
言語 Rust
(1.77.0)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 687 bytes
コンパイル時間 11,101 ms
コンパイル使用メモリ 392,156 KB
実行使用メモリ 19,464 KB
最終ジャッジ日時 2024-05-03 22:05:45
合計ジャッジ時間 12,650 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
10,680 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 0 ms
6,944 KB
testcase_04 AC 20 ms
10,620 KB
testcase_05 AC 43 ms
19,396 KB
testcase_06 AC 43 ms
19,464 KB
testcase_07 AC 41 ms
19,400 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 44 ms
19,448 KB
testcase_11 AC 17 ms
9,588 KB
testcase_12 AC 42 ms
18,700 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn solve(n: usize, k: usize) -> usize {
    let mut flgs: Vec<bool> = vec![true; n+1];
    flgs[0] = false;
    flgs[1] = false;
    let mut pcount: Vec<usize> = vec![0; n+1];
    for i in 2..=(n/2) {
        if !flgs[i] { continue; }
        for j in 2..=n/i {
            flgs[i*j] = false;
            pcount[i*j] += 1;
        }
    }
    pcount.iter().enumerate()
        .filter(|pair| *pair.1 >= k - if flgs[pair.0] { 1 } else { 0 })
        .count()
}

fn main() {
    let mut nk = String::new();
    std::io::stdin().read_line(&mut nk).ok();
    let nk: Vec<usize> = nk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    println!("{}", solve(nk[0], nk[1]));
}
0