結果

問題 No.1514 Squared Matching
ユーザー phsplsphspls
提出日時 2022-11-03 16:50:02
言語 Rust
(1.77.0)
結果
AC  
実行時間 3,611 ms / 4,000 ms
コード長 819 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 141,388 KB
実行使用メモリ 441,520 KB
最終ジャッジ日時 2023-09-25 01:25:25
合計ジャッジ時間 61,653 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 3,611 ms
441,516 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 30 ms
8,804 KB
testcase_07 AC 540 ms
86,116 KB
testcase_08 AC 3,434 ms
425,616 KB
testcase_09 AC 2,961 ms
372,332 KB
testcase_10 AC 3,230 ms
403,120 KB
testcase_11 AC 3,363 ms
420,096 KB
testcase_12 AC 3,517 ms
431,732 KB
testcase_13 AC 3,510 ms
437,188 KB
testcase_14 AC 3,534 ms
439,636 KB
testcase_15 AC 3,484 ms
440,708 KB
testcase_16 AC 3,537 ms
441,064 KB
testcase_17 AC 3,535 ms
441,336 KB
testcase_18 AC 3,601 ms
441,432 KB
testcase_19 AC 3,503 ms
441,520 KB
testcase_20 AC 3,593 ms
441,460 KB
testcase_21 AC 3,517 ms
441,460 KB
testcase_22 AC 573 ms
89,944 KB
testcase_23 AC 1,263 ms
177,972 KB
testcase_24 AC 2,036 ms
265,792 KB
testcase_25 AC 2,833 ms
353,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    for i in 2..=(n as f64).sqrt().ceil() as usize {
        if !flgs[i] { continue; }
        let modval = i*i;
        for j in 1..=n/i {
            flgs[i*j] = false;
            while factors[i*j] % modval == 0 {
                factors[i*j] /= modval;
            }
        }
    }

    factors
}

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 = 0;
    for i in 1..=n {
        let limit = n / factors[i];
        result += (limit as f64).sqrt().floor() as usize;
    }
    println!("{}", result);
}
0