package 高蕊;
import java.util.Scanner;
public class Javav
{
public static int get_god(int n1,int n2) /*最大公约数*/
{
int god=0;
if(n1<n2)/*判断A和B的大小*/
{
n1=n1+n2;
n2=n1-n2;
n1=n1-n2;
}
if(n1%n2==0)/*A是不是B的倍数*/
god=n2;
while(n1%n2>0)
{
n1=n1%n2;
if(n1<n2)
{
n1=n1+n2;
n2=n1-n2;
n1=n1-n2;
}
if(n1%n2==0)
god=n2;
}
return god;/*最大公约数返回*/
}
public static int get_icm(int n1,int n2)/*最小公倍数*/
{
return n1*n2/get_god(n1,n2);
}
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int n1=input.nextInt();/*调用最大公约*/
int n2=input.nextInt();/*调用最小公倍数*/
System.out.println("("+n1+","+n2+")"+"="+get_god(n1,n2));/*输出*/
System.out.println("("+n1+","+n2+")"+"="+get_icm(n1,n2));/*输出*/
}
}
原文:https://www.cnblogs.com/abcde12345/p/8763286.html