AcWing 809. 最小公倍数 - Java
原题链接
中等
作者:
KYCygni
,
2021-03-21 13:13:46
,
所有人可见
,
阅读 257
Java 代码
import java.util.Scanner;
public class Main
{
public static int gcd (int m, int n)
{
// swap without using temp
if (m < n)
{
m = m - n;
n = m + n; // n is m now
m = n - m; // m is n now
}
if ( m % n == 0)
return n;
return gcd (n, m % n );
}
public static int lcm (int m, int n)
{
return m * n / gcd (m, n);
}
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int m = cin.nextInt();
int n = cin.nextInt();
System.out.println (lcm(m, n));
}
}