結果

問題 No.1723 [Cherry 3rd Tune *] Dead on
ユーザー seinyanseinyan
提出日時 2021-10-30 20:26:35
言語 Rust
(1.77.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,767 bytes
コンパイル時間 1,230 ms
コンパイル使用メモリ 164,608 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 16:27:43
合計ジャッジ時間 2,879 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 12 ms
5,376 KB
testcase_05 AC 6 ms
5,376 KB
testcase_06 AC 6 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 21 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 17 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 8 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 14 ms
5,376 KB
testcase_16 AC 17 ms
5,376 KB
testcase_17 AC 16 ms
5,376 KB
testcase_18 AC 17 ms
5,376 KB
testcase_19 AC 13 ms
5,376 KB
testcase_20 AC 6 ms
5,376 KB
testcase_21 AC 13 ms
5,376 KB
testcase_22 AC 7 ms
5,376 KB
testcase_23 AC 17 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 19 ms
5,376 KB
testcase_26 AC 16 ms
5,376 KB
testcase_27 AC 7 ms
5,376 KB
testcase_28 AC 15 ms
5,376 KB
testcase_29 AC 17 ms
5,376 KB
testcase_30 AC 20 ms
5,376 KB
testcase_31 AC 16 ms
5,376 KB
testcase_32 AC 18 ms
5,376 KB
testcase_33 AC 8 ms
5,376 KB
testcase_34 AC 7 ms
5,376 KB
testcase_35 AC 7 ms
5,376 KB
testcase_36 AC 21 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 1 ms
5,376 KB
testcase_40 AC 4 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 5 ms
5,376 KB
testcase_46 AC 5 ms
5,376 KB
testcase_47 AC 6 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashMap;
use std::io;

fn main() {
    let v = input_nums();
    let (x, a, y, b) = (v[0], v[1], v[2], v[3]);

    let xv = prime_factorization(x);
    let yv = prime_factorization(y);

    let x_hmp = get_pf_hashmap(&xv);
    let y_hmp = get_pf_hashmap(&yv);

    let mut result = true;

    for (k, v) in y_hmp {
        if k == 1 {
            result = true;
            break;
        }
        if !x_hmp.contains_key(&k) {
            result = false;
            break;
        }
        if x_hmp[&k] * a < v * b {
            result = false;
            break;
        }
    }
    println!("{}", if result { "Yes" } else { "No" });
}

fn prime_factorization(mut num: u64) -> Vec<u64> {
    let mut v = Vec::new();
    let mut div = 2;
    let max_div = if num >= 30 {
        (num as f64).sqrt() as u64
    } else {
        num
    };

    while div <= max_div {
        if num % div == 0 {
            v.push(div);
            num /= div;
        } else {
            div += 1;
        }
    }
    if v.len() == 0 {
        v.push(num);
    }
    v
}

fn get_pf_hashmap(pf_v: &Vec<u64>) -> HashMap<u64, u64> {
    let mut hm = HashMap::new();
    let mut count = 0;
    let mut cor = 2;
    for i in 0..pf_v.len() {
        if cor == pf_v[i] {
            count += 1;
        } else {
            if count != 0 {
                hm.insert(cor, count);
            }
            cor = pf_v[i];
            count = 1;
        }
        if i == pf_v.len() - 1 {
            hm.insert(cor, count);
        }
    }
    hm
}

fn input_nums() -> Vec<u64> {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let mut v = Vec::new();
    for n in s.split_whitespace() {
        v.push(n.parse().unwrap());
    }
    v
}
0