結果

問題 No.1514 Squared Matching
ユーザー phsplsphspls
提出日時 2022-11-03 17:35:41
言語 Rust
(1.77.0)
結果
AC  
実行時間 1,548 ms / 4,000 ms
コード長 1,047 bytes
コンパイル時間 3,421 ms
コンパイル使用メモリ 141,344 KB
実行使用メモリ 392,832 KB
最終ジャッジ日時 2023-09-25 01:56:13
合計ジャッジ時間 26,669 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1,548 ms
392,776 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 19 ms
8,068 KB
testcase_07 AC 235 ms
76,624 KB
testcase_08 AC 1,330 ms
378,476 KB
testcase_09 AC 1,106 ms
331,296 KB
testcase_10 AC 1,161 ms
358,608 KB
testcase_11 AC 1,212 ms
373,552 KB
testcase_12 AC 1,250 ms
383,788 KB
testcase_13 AC 1,264 ms
389,052 KB
testcase_14 AC 1,271 ms
391,104 KB
testcase_15 AC 1,278 ms
392,004 KB
testcase_16 AC 1,283 ms
392,572 KB
testcase_17 AC 1,278 ms
392,832 KB
testcase_18 AC 1,276 ms
392,748 KB
testcase_19 AC 1,281 ms
392,816 KB
testcase_20 AC 1,282 ms
392,736 KB
testcase_21 AC 1,283 ms
392,816 KB
testcase_22 AC 246 ms
80,244 KB
testcase_23 AC 494 ms
158,456 KB
testcase_24 AC 735 ms
236,540 KB
testcase_25 AC 999 ms
314,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn get_primes(n: usize) -> Vec<bool> {
    let mut flgs = vec![true; n+1];
    flgs[0] = false;
    flgs[1] = false;

    for i in 2..=(n as f64).sqrt().ceil() as usize {
        if !flgs[i] { continue; }
        for j in i..=n/i {
            flgs[i*j] = false;
        }
    }

    flgs
}

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

    let limit = (n as f64).sqrt().ceil() as usize;
    let primes = get_primes(limit);
    let mut factors = (0..=n).collect::<Vec<_>>();
    for i in 0..=limit {
        if !primes[i] { continue; }
        let modval = i*i;
        for j in 1.. {
            let target = j * modval;
            if target > n { break; }
            while factors[target] % modval == 0 {
                factors[target] /= modval;
            }
        }
    }
    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