https://atcoder.jp/contests/arc165/tasks/arc165_a
Nが素数か素数べきならNoだとすぐにわかります。それ以外なら、和のほうで足りない分を1で埋めればいいだけです。
// Sum equals LCM #![allow(non_snake_case)] //////////////////// library //////////////////// fn read<T: std::str::FromStr>() -> T { let mut line = String::new(); std::io::stdin().read_line(&mut line).ok(); line.trim().parse().ok().unwrap() } fn YesNo(b: bool) -> String { return if b { "Yes".to_string() } else { "No".to_string() } } fn div_pow(mut n: i32, p: i32) -> (i32, i32) { let mut e: i32 = 0; while n % p == 0 { e += 1; n /= p } (e, n) } fn factor(n: i32) -> Vec<(i32, i32)> { if n == 1 { return vec![] } for p in (2..).take_while(|&p| p * p <= n) { if n % p == 0 { let (e, m) = div_pow(n, p); let mut fs: Vec<(i32, i32)> = vec![(p, e)]; fs.extend(factor(m)); return fs } } vec![(n, 1)] } //////////////////// process //////////////////// fn F_each(n: i32) -> bool { let fs = factor(n); fs.len() > 1 } fn F(T: usize) { for _ in 0..T { let n: i32 = read(); println!("{}", YesNo(F_each(n))) } } fn main() { let T = read(); F(T) }