题解 | #小乐乐与欧几里得#
小乐乐与欧几里得
https://www.nowcoder.com/practice/da13e0cf321e4df9acd0fdf0a433cbb0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Long num1 = sc.nextLong(); Long num2 = sc.nextLong(); Long t = 0L; if (num1 < num2) { t = num1; num1 = num2; num2 = t; } Long gcd = getGcd(num1, num2); Long lcm = getLcm(num1, num2, gcd); System.out.println(gcd + lcm); } //注意代码能通过,但是提不能通过,为什么? //保持提交的时候,例子的数范围超过Int的最大值最导致计算出的结果错误 public static Long getGcd(Long m, Long n) { while (m % n != 0) { Long temp = m % n; m = n; n = temp; } return n; } public static Long getLcm(Long m, Long n, Long gcd) { return m * n / gcd; } }