結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー phspls
提出日時 2022-10-31 22:20:57
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 1,307 bytes
コンパイル時間 16,264 ms
コンパイル使用メモリ 378,784 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 10:11:33
合計ジャッジ時間 21,368 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 4 WA * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

const LIMIT: usize = 31;

fn solve(factors: &Vec<Vec<usize>>) -> usize {
    let mut x = String::new();
    std::io::stdin().read_line(&mut x).ok();
    let x: usize = x.trim().parse().unwrap();
    let mut target = x;
    let mut xfacts = vec![0usize; LIMIT+1];
    for i in 2..=LIMIT {
        while target % i == 0 {
            target /= i;
            xfacts[i] += 1;
        }
    }
    for i in 2..=LIMIT {
        let mut tcnt = 1usize;
        let mut fcnt = 1usize;
        for j in 2..=LIMIT {
            if factors[i][j] == 0 { continue; }
            tcnt *= 1 + xfacts[j];
            fcnt *= 1 + factors[i][j];
        }
        if tcnt * 2 == fcnt {
            return x * i;
        }
    }
    LIMIT * x
} 

fn main() {
    let mut t = String::new();
    std::io::stdin().read_line(&mut t).ok();
    let t: usize = t.trim().parse().unwrap();
    let mut result = Vec::with_capacity(t);
    let mut factors = vec![vec![0usize; LIMIT+1]; LIMIT+1];
    for i in 2..=LIMIT {
        let mut target = i;
        for j in 2..=LIMIT {
            while target % j == 0 {
                factors[i][j] += 1;
                target /= j;
            }
        }
    }
    for _ in 0..t {
        result.push(solve(&factors));
    }
    for &v in result.iter() {
        println!("{}", v);
    }
}
0