結果

問題 No.1514 Squared Matching
ユーザー phsplsphspls
提出日時 2022-12-01 21:31:09
言語 Rust
(1.77.0)
結果
MLE  
実行時間 -
コード長 838 bytes
コンパイル時間 4,572 ms
コンパイル使用メモリ 154,752 KB
実行使用メモリ 783,196 KB
最終ジャッジ日時 2024-04-17 09:17:27
合計ジャッジ時間 58,495 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 MLE -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 30 ms
13,796 KB
testcase_07 AC 679 ms
151,080 KB
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 AC 546 ms
158,076 KB
testcase_23 AC 1,073 ms
314,196 KB
testcase_24 AC 1,853 ms
470,656 KB
testcase_25 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

fn get_factors(n: usize) -> Vec<usize> {
    let mut flgs = vec![true; n+1];
    flgs[0] = false;
    flgs[1] = false;
    let mut ret = (0..=n).collect::<Vec<_>>();

    for i in 2..=n {
        if !flgs[i] { continue; }
        let base = i * i;
        for j in i..=n/i {
            let idx = i*j;
            flgs[idx] = false;
            while ret[idx] % base == 0 {
                ret[idx] /= base;
            }
        }
    }

    ret
}

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

    let factors = get_factors(n);
    let mut cnts = vec![0usize; n+1];
    for &v in factors.iter() {
        cnts[v] += 1;
    }
    let mut result = 0usize;
    for a in 1..=n {
        result += cnts[factors[a]];
    }
    println!("{}", result);
}
0