fn read() -> Vec where ::Err: std::fmt::Debug, { let mut b = String::new(); std::io::stdin().read_line(&mut b).unwrap(); b.split_whitespace() .map(|x| x.trim().parse::().unwrap()) .collect() } fn gcd(x: u64, y: u64) -> u64 { let (x, y) = if x < y { (x, y) } else { (y, x) }; if x == 0 { return y; } return gcd(x, y % x); } fn main() { let iv = read::(); let a = iv[0]; let b = iv[1]; //let ag = gcd(a + b, a); //let bg = gcd(a + b, b); if a == b && (a & (a - 1)) == 0 { println!("{}", a + b); return; } println!("{}", gcd(a, b)); } /* x=a+b, a * b xa = gcd(x, a) xb = gcd(x, b) x = k1 * xa x = k2 * xb a = k5 * xa b = k6 * xb xab = gcd(x, a*b) = gcd(a+b, a * b) a*b = k4 * xab = (k5 * xa) * b = (k6*xb) * a x = k3 * xab = k1 * xa = k2 * xb */