标签:
正整数A和正整数B 的最小公倍数是指 能被A和B整除的最小的正整数值,设计一个算法,求输入A和B的最小公倍数。
输入两个正整数A和B。
输出A和B的最小公倍数。
5
7
35
import java.util.Scanner;
/**
* Author: 王俊超
* Date: 2015-12-28 13:51
* All Rights Reserved !!!
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Scanner scanner = new Scanner(Main.class.getClassLoader().getResourceAsStream("data.txt"));
while (scanner.hasNext()) {
int m = scanner.nextInt();
int n = scanner.nextInt();
System.out.println(m / gcd(m, n) * n);
}
scanner.close();
}
private static int gcd(int max, int min) {
int tmp;
if (max < min) {
tmp = max;
max = min;
min = tmp;
}
while (max % min != 0) {
tmp = min;
min = max % min;
max = tmp;
}
return min;
}
}
标签:
原文地址:http://blog.csdn.net/derrantcm/article/details/51422053