public class Test_最大公约数最小公倍数 {
public static void main(String[] args) {
print(5550, 4);
}
private static void print(int m, int n) {
// 最大公约数更相减损之术
int a = m;
int b = n;
for (int x = 0; x < m + n; x++) {
if (a == b) {
System.out.println("最大公约数=" + a);
System.out.println("最小公倍数="+m*n/a);
break;
}
if (a < b) {
int t = a;
a = b;
b = t;
}
int t = b;
a = a - b;
b = t;
}
}
}
|
|