結果

問題 No.1058 素敵な数
ユーザー phsplsphspls
提出日時 2020-05-23 19:31:54
言語 Rust
(1.77.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,028 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 158,080 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 07:01:20
合計ジャッジ時間 1,481 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,248 KB
testcase_01 AC 6 ms
5,376 KB
testcase_02 AC 5 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 6 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn get_upper_primes() -> Vec<usize> {
    let mut flgs: Vec<bool> = vec![true; 1_000_001];
    flgs[0] = false;
    flgs[1] = false;
    let mut result: Vec<usize> = vec![];
    for i in 2..=1_000_000 {
        if !flgs[i] { continue; }
        if i > 100_000 {
            result.push(i);
            if result.len() == 9 { break; }
        }
        for j in i..=1_000_000/i {
            flgs[j*i] = false;
        }
    }
    result
}

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();

    let mut result: Vec<usize> = vec![];
    result.push(1);
    let cand_bases = get_upper_primes();
    let mut cands: Vec<usize> = vec![];
    for a in cand_bases.iter() {
        for b in cand_bases.iter() {
            let val = a * b;
            if !cands.contains(&val) {
                cands.push(val);
            }
        }
    }
    cands.sort();
    for i in 0..9 {
        result.push(cands[i]);
    }
    println!("{}", result[n-1]);
}
0