結果

問題 No.106 素数が嫌い!2
ユーザー neko_the_shadowneko_the_shadow
提出日時 2024-02-07 10:42:38
言語 Rust
(1.77.0)
結果
AC  
実行時間 75 ms / 5,000 ms
コード長 797 bytes
コンパイル時間 1,199 ms
コンパイル使用メモリ 181,644 KB
実行使用メモリ 19,396 KB
最終ジャッジ日時 2024-02-07 10:42:49
合計ジャッジ時間 2,660 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,656 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 25 ms
10,656 KB
testcase_05 AC 73 ms
19,396 KB
testcase_06 AC 72 ms
19,396 KB
testcase_07 AC 75 ms
19,396 KB
testcase_08 AC 4 ms
6,548 KB
testcase_09 AC 4 ms
6,548 KB
testcase_10 AC 70 ms
19,396 KB
testcase_11 AC 22 ms
9,620 KB
testcase_12 AC 72 ms
18,732 KB
testcase_13 AC 1 ms
6,548 KB
testcase_14 AC 0 ms
6,548 KB
testcase_15 AC 1 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::stdin;

fn main() {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    let token = line.split_whitespace().map(|v|v.parse().unwrap()).collect::<Vec<usize>>();
    let n = token[0];
    let k = token[1];

    let mut is_prime = vec![true; n+1];
    is_prime[0] = false;
    is_prime[1] = false;
    for i in (2..=n).take_while(|v| v*v<=n) {
        if !is_prime[i] {
            continue;
        }
        for j in (i+i..=n).step_by(i) {
            is_prime[j] = false;
        }
    }

    let mut count = vec![0usize; n+1];
    for i in 0..=n {
        if !is_prime[i] {
            continue;
        }
        for j in (i..=n).step_by(i) {
            count[j] += 1
        }
    }
    println!("{}", count.into_iter().filter(|&v| v>=k).count())
}


0