package com.suanfa.test;
import java.util.Scanner;
//辗转相除法、更相减损法
public class GCD_LCM {
public static void main(String[] args) {
System.out.println("请输入格式为“a b”的两个数:");
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
System.out.println("最大公约数为:"+gcd(a,b));
System.out.println("最小公倍数为:"+lcm(a,b));
}
public static int gcd(int a,int b) {
int temp=0;
while (b!=0) {
temp=a%b;
a=b;
b=temp;
}
return a;
}
public static int gcd0(int a,int b) {
while (a != b) {
if(a>b)a-=b;
else b-=a;
}
return a;
}
public static int lcm(int a,int b) {
return a*b/gcd(a,b);
}
}