結果

問題 No.1659 Product of Divisors
ユーザー phspls
提出日時 2023-01-17 02:19:28
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,069 bytes
コンパイル時間 14,056 ms
コンパイル使用メモリ 405,232 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-31 20:27:39
合計ジャッジ時間 15,419 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashMap;

const MOD: usize = 1e9 as usize + 7;

fn power(base: usize, times: usize) -> usize {
    if times == 0 { return 1usize; }
    if times == 1 { return base; }
    let temp = power(base, times/2);
    temp * temp % MOD * power(base, times%2) % MOD
}

fn main() {
    let mut nk = String::new();
    std::io::stdin().read_line(&mut nk).ok();
    let nk: Vec<usize> = nk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nk[0];
    let k = nk[1];

    let mut mapping = HashMap::new();
    let mut target = n;
    for i in 2..=(n as f64).sqrt().floor() as usize {
        while target % i == 0 {
            target /= i;
            *mapping.entry(i).or_insert(0usize) += 1;
        }
    }
    if target > 1 {
        mapping.insert(target, 1);
    }
    let mut result = 1usize;
    for &cnt in mapping.values() {
        result *= (k+1..=k+cnt).fold(1usize, |x, y| x % MOD * (y % MOD) % MOD) * power((1..=cnt).fold(1usize, |x, y| x*y%MOD), MOD-2) % MOD;
        result %= MOD;
    }
    println!("{}", result);
}
0