题解 | #求最小公倍数#
求最小公倍数
https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
欧几里得算法 import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (scanner.hasNext()) { int num1 = scanner.nextInt(); int num2 = scanner.nextInt(); int gcd = gcd ( num1, num2 ); int lcm = num1 * num2 / gcd; System.out.println(lcm); } /*主方法分割线-----------------------------------*/ } public static int gcd(int a, int b) { while (b != 0) { int tmp = b; b = a % tmp; a = tmp; } return a; } }