题解 | #求最小公倍数#
求最小公倍数
https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
- 最小公倍数 = a * b / 最大公约数
- a b的最大公约数
use std::io::{self, *};
fn main() {
let stdin = io::stdin();
let input = stdin.lock().lines().next().unwrap().unwrap();
let numbers:Vec<i32> = input.split(" ").map(|x| x.parse::<i32>().unwrap()).collect();
let mut a = numbers[0];
let mut b = numbers[1];
//a b的最大公约数
let mut big = if a > b {a} else {b};
let mut small = if a > b {b} else {a};
while small!= 0 {
let temp = big % small;
big = small;
small = temp;
}
// 最小公倍数 = a * b / 最大公约数
println!("{}", a * b / big);
}
#rust#
查看23道真题和解析

