https://atcoder.jp/contests/math-and-algorithm/tasks/math_and_algorithm_bo
三重に回せばいいので余裕で間に合います。
// Two Conditions #![allow(non_snake_case)] use std::cmp::{min, max}; //////////////////// 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 read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() } fn YesNo(b: bool) -> String { return if b { "Yes".to_string() } else { "No".to_string() } } //////////////////// process //////////////////// fn read_input() -> (i32, i32, i32) { let v = read_vec(); let N = v[0]; let X = v[1]; let Y = v[2]; (N, X, Y) } fn f(N: i32, X: i32, Y: i32) -> bool { // a<=b<=c<=d for a in max(1, X-N*3)..min(301, X/4+1) { let X1 = X - a; for b in max(a, X1-N*2)..min(301, X1/3+1) { let X2 = X1 - b; for c in max(b, X2-N)..min(301, X2/2+1) { let d = X2 - c; if c > d && d <= N { break } if a * b * c * d == Y { return true } } } } false } fn main() { let (N, X, Y) = read_input(); println!("{}", YesNo(f(N, X, Y))) }