import java.util.Scanner; //求两个数的最大公约数,最小共倍数。 public class CommonMaxDivisor { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int m=scanner.nextInt(); int n=scanner.nextInt(); scanner.close(); CommonMaxDivisor cmd=new CommonMaxDivisor(); int result=cmd.commonMaxDivisor(n, m); int result1=cmd.commonMinMultiple(n, m); System.out.println(result+","+result1); } public int commonMaxDivisor(int n,int m){ int min=n<m?n:m; int max=n>m?n:m; int result=1; for(int i=1;i<min;i++){ if(max%i==0&&min%i==0) result=i; } return result; } public int commonMinMultiple(int n,int m){ return m*n/commonMaxDivisor(n,m); } }
时间: 2024-12-26 00:58:34