結果

問題 No.1514 Squared Matching
ユーザー phsplsphspls
提出日時 2022-11-10 11:35:37
言語 Rust
(1.77.0)
結果
AC  
実行時間 3,728 ms / 4,000 ms
コード長 833 bytes
コンパイル時間 1,179 ms
コンパイル使用メモリ 143,632 KB
実行使用メモリ 441,524 KB
最終ジャッジ日時 2023-09-30 20:31:39
合計ジャッジ時間 62,619 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 3,728 ms
441,468 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 30 ms
8,884 KB
testcase_07 AC 540 ms
86,092 KB
testcase_08 AC 3,487 ms
425,512 KB
testcase_09 AC 2,984 ms
372,364 KB
testcase_10 AC 3,269 ms
403,244 KB
testcase_11 AC 3,326 ms
419,956 KB
testcase_12 AC 3,502 ms
431,492 KB
testcase_13 AC 3,549 ms
437,380 KB
testcase_14 AC 3,591 ms
439,660 KB
testcase_15 AC 3,580 ms
440,700 KB
testcase_16 AC 3,563 ms
441,240 KB
testcase_17 AC 3,653 ms
441,496 KB
testcase_18 AC 3,555 ms
441,456 KB
testcase_19 AC 3,555 ms
441,524 KB
testcase_20 AC 3,688 ms
441,504 KB
testcase_21 AC 3,574 ms
441,476 KB
testcase_22 AC 570 ms
89,992 KB
testcase_23 AC 1,274 ms
177,852 KB
testcase_24 AC 2,039 ms
265,776 KB
testcase_25 AC 2,810 ms
353,644 KB
権限があれば一括ダウンロードができます

ソースコード

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 as f64).sqrt().ceil() as usize {
        if !flgs[i] { continue; }
        for j in 1..=n/i {
            let idx = i*j;
            flgs[idx] = false;
            let base = i*i;
            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 result = 0usize;
    for i in 1..=n {
        let right = n / factors[i];
        result += (right as f64).sqrt().floor() as usize;
    }
    println!("{}", result);
}
0