java求最小公倍数
求最小公倍数
http://www.nowcoder.com/questionTerminal/22948c2cad484e0291350abad86136c3
图片及思路来源:https://www.cnblogs.com/echoing/p/7878954.html
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int a = sc.nextInt(); int b = sc.nextInt(); int gcd = get_gcd(a,b); int lcm = a * b / gcd; System.out.println(lcm); } } private static int get_gcd(int a, int b){ if(a < b){ int temp = a; a = b; b = temp; } if(a % b == 0){ return b; } int yu = 0; while(a % b != 0){ yu = a % b; if(yu > b){ a = yu; }else{ a = b; b = yu; } } return b; } }