結果

問題 No.2207 pCr検査
ユーザー zaichuzaichu
提出日時 2023-02-05 10:52:54
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,232 bytes
コンパイル時間 1,308 ms
コンパイル使用メモリ 152,636 KB
実行使用メモリ 6,384 KB
最終ジャッジ日時 2023-09-17 04:13:51
合計ジャッジ時間 7,505 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashMap;

fn main() {
    let n = read_input();
    let factorization = factorize(n);
    let mut p_candidates = HashMap::new();

    for (p, e) in factorization.iter() {
        for i in 0..=*e {
            let c = comb(*p as i64, i as i64);
            *p_candidates.entry(c).or_insert(0) += 1;
        }
    }

    for (p, e) in factorization.iter() {
        if p_candidates.contains_key(p) && *p_candidates.get(p).unwrap() == *e as usize {
            println!("{} {}", p, e);
            return;
        }
    }

    println!("-1 -1");
}

fn read_input() -> i64 {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let n = input.trim().parse::<i64>().unwrap();
    n
}

fn factorize(n: i64) -> HashMap<i64, i64> {
    let mut factorization = HashMap::new();
    let mut n = n;

    for i in 2.. {
        if n == 1 {
            break;
        }

        if n % i == 0 {
            *factorization.entry(i as i64).or_insert(0) += 1;
            n /= i;
        }
    }

    factorization
}

fn comb(n: i64, r: i64) -> i64 {
    if r > n {
        return 0;
    }

    let mut res = 1;

    for i in 0..r {
        res = res * (n - i) / (i + 1);
    }

    res
}
0