結果

問題 No.2318 Phys Bone Maker
ユーザー koba-e964koba-e964
提出日時 2023-05-27 01:34:24
言語 Rust
(1.77.0)
結果
AC  
実行時間 687 ms / 3,000 ms
コード長 2,080 bytes
コンパイル時間 3,726 ms
コンパイル使用メモリ 163,336 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-26 15:05:16
合計ジャッジ時間 8,247 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 687 ms
4,376 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 8 ms
4,376 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 7 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 7 ms
4,380 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 12 ms
4,376 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 12 ms
4,384 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 8 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 11 ms
4,380 KB
testcase_18 AC 11 ms
4,380 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 6 ms
4,500 KB
testcase_23 AC 7 ms
4,376 KB
testcase_24 AC 10 ms
4,376 KB
testcase_25 AC 9 ms
4,376 KB
testcase_26 AC 9 ms
4,376 KB
testcase_27 AC 10 ms
4,376 KB
testcase_28 AC 6 ms
4,376 KB
testcase_29 AC 6 ms
4,376 KB
testcase_30 AC 5 ms
4,380 KB
testcase_31 AC 11 ms
4,376 KB
testcase_32 AC 10 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 9 ms
4,380 KB
testcase_35 AC 49 ms
4,376 KB
testcase_36 AC 256 ms
4,380 KB
testcase_37 AC 283 ms
4,376 KB
testcase_38 AC 317 ms
4,380 KB
testcase_39 AC 412 ms
4,376 KB
testcase_40 AC 450 ms
4,376 KB
testcase_41 AC 510 ms
4,376 KB
testcase_42 AC 557 ms
4,376 KB
testcase_43 AC 14 ms
4,376 KB
testcase_44 AC 138 ms
4,380 KB
testcase_45 AC 124 ms
4,380 KB
testcase_46 AC 637 ms
4,376 KB
testcase_47 AC 12 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn gcd(mut x: i64, mut y: i64) -> i64 {
    while y != 0 {
        let r = x % y;
        x = y;
        y = r;
    }
    x
}

// https://yukicoder.me/problems/no/2318 (3)
// N の約数は多くとも 6720 個程度。
fn main() {
    let n: i64 = get();
    let mut div = vec![];
    {
        let mut d = 1;
        while d * d <= n {
            if n % d == 0 {
                div.push(d);
                if n != d * d {
                    div.push(n / d);
                }
            }
            d += 1;
        }
    }
    div.sort();
    let m = div.len();
    let mut hm = std::collections::HashMap::new();
    for i in 0..m {
        let mut c = 0;
        for j in 0..i + 1 {
            if div[i] % div[j] == 0 {
                c += 1;
            }
        }
        hm.insert(div[i], c);
    }
    let mut dp = vec![0; m];
    dp[0] += 1;
    const MOD: i64 = 998_244_353;
    for i in 1..m {
        for j in 0..i {
            if div[i] % div[j] == 0 {
                // #{x | lcm(div[j], x) = div[i]} = #{x | lcm(div[j], x) = div[i]}
                let q = div[i] / div[j];
                let mut cap = div[i];
                loop {
                    let g = gcd(cap, q);
                    if g == 1 { break; }
                    cap /= g;
                }
                let coef = hm[&cap];
                dp[i] += dp[j] * coef;
            }
        }
        dp[i] %= MOD;
    }
    println!("{}", dp[m - 1]);
}
0