use proconio::{fastout, input}; #[fastout] fn main() { input! { t: usize, dxy: [(usize, usize, usize); t], } for &(d, x, y) in &dxy { println!("{}", solve(d, x, y)); } } fn solve(side_len: usize, x: usize, y: usize) -> usize { let d = gcd(x as i64, y as i64) as usize; let coef1 = (x * d / y).min((side_len - y) * d / x); let coef2 = ((side_len - x) * d / y).min(y * d / x); (x.pow(2) + y.pow(2)) / d * coef1.max(coef2) } fn gcd(mut a: i64, mut b: i64) -> i64 { a = a.abs(); b = b.abs(); while b != 0 { let r = a % b; a = b; b = r; } a }