"Huawei OJ" "Algorithm Total chapter" "Huawei OJ" "067-seeking least common multiple" "Project download" topic description
正整数A和正整数B 的最小公倍数是指 能被A和B整除的最小的正整数值,设计一个算法,求输入A和B的最小公倍数。
Enter a description
输入两个正整数A和B。
Output description
输出A和B的最小公倍数。
Input example
57
Output example
35
Algorithm implementation
ImportJava.util.Scanner;/** * Author: Wang Junshu * date:2015-12-28 13:51 * All rights Reserved!!! */ Public class Main { Public Static void Main(string[] args) {Scanner Scanner =NewScanner (system.in);//Scanner Scanner = new Scanner (Main.class.getClassLoader (). getResourceAsStream ("Data.txt")); while(Scanner.hasnext ()) {intm = Scanner.nextint ();intn = scanner.nextint (); System.out.println (M/GCD (M, N) * n); } scanner.close (); }Private Static int GCD(intMaxintMin) {inttmpif(Max < min) {tmp = max; max = min; min = tmp; } while(max% min! =0) {tmp = min; min = max% min; max = tmp; }returnMin }}
"Huawei OJ" "067-seeking least common multiple"