import java.util.*; public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); int m = console.nextInt(); int n = console.nextInt(); int result = getCM(m, n); System.out.println(result); } public static int getCM(int m, int n){ return m*n/gcd(m,n); } public static int gcd(int m,int n){ if (n==0) return m; return gcd(n,m%n); } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int m = in.nextInt(); int n = in.nextInt(); System.out.println(getCM(m,n)); } public static int getCM(int m,int n){ return m*n/gcd(m,n); } public static int gcd(int m,int n){ if(n==0) return m; return gcd(n,m%n); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); int m = console.nextInt(); int n = console.nextInt(); int result = getCM(m, n); System.out.println(result); } public static int getCM(int m, int n) { //write your code here...... return (m * n) / gcd(m, n); } public static int gcd(int m, int n) { while (true) { //用大数减去小数并将结果保存起来 if (m > n) { m -= n; } else if (m < n) { n -= m; } else { //如果两个数相等时,则这个数就是最大公约数 return m; } } } 两个数的乘积等于这两个数的最大公约数与最小公倍数的积.求出最大公约数.最小公倍数迎刃而解.
import java.util.*; public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); int m = console.nextInt(); int n = console.nextInt(); int result = getCM(m, n); System.out.println(result); } public static int getCM(int m, int n){ //write your code here...... // 最小公倍数=n*m/最大公约数 return n*m/gcd(m,n); } public static int gcd(int m, int n){ if(n==0)return m; return gcd(n,m%n); } } //用这个来理解上面的递归 // 1997 / 615 = 3 (余 152) // 615 / 152 = 4(余7) // 152 / 7 = 21(余5) // 7 / 5 = 1 (余2) // 5 / 2 = 2 (余1) // 2 / 1 = 2 (余0)
import java.util.*; public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.println(getCM(console.nextInt(), console.nextInt())); console.close(); } //最小公倍数等于两数之积除以最大公约数 public static int getCM(int m, int n) { return (m * n) / getCD(m, n) ; } //欧几里得算法又称辗转相除法: //两数相除,以除数和余数反复做除法运算,当余数为 0 时,取当前算式除数为最大公约数 public static int getCD(int m, int n) { if (n == 0) return m; else return getCD(n, m % n);//辗转相除除尽时,最后一个除数就是最大公约数 } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); int m = console.nextInt(); int n = console.nextInt(); int result = getCM(m, n); System.out.println(result); } public static int getCM(int m, int n) { //write your code here...... if (m % n == 0) { return m; } else if (n % m == 0) { return n; } if (m > n) { int temp = m; m = n; n = temp; } for (int i = n;; i += n) { if (i % m == 0) { return i; } } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); int m = console.nextInt(); int n = console.nextInt(); int result = getCM(m, n); System.out.println(result); } public static int getCM(int m, int n){ //write your code here...... return m*n/gcd(m,n); } public static int gcd(int m,int n){ if(m%n==0){ return n; }else{ return gcd(n,m%n); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); int m = console.nextInt(); int n = console.nextInt(); int result = getCM(m, n); System.out.println(result); } public static int getCM(int m, int n) { //write your code here...... int max = Math.max(m, n); int lcm = max; while (true) { if (lcm % m == 0 && lcm % n == 0) { break; } lcm += max; } return lcm; } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); int m = console.nextInt(); int n = console.nextInt(); int result = getCM(m, n); System.out.println(result); } public static int getCM(int m, int n) { //write your code here...... for (int i = m ; i <= m * n; i++) { if ( i % m == 0 && i % n == 0) { return i ; } } return 0; } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int a = in.nextInt(); int b = in.nextInt(); int c = test(a,b); System.out.println(c); } public static int test(int i,int j){ int a = i>j?i:j; int b = i>j?j:i; int c = 0; int d = 1; int e = 0; while(true){ c = a*d; d = d+1; if(c%b==0) { e = c; break; } } return e; } }
// 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { //编写一个方法,该方法的返回值是两个不大于100的正整数的最小公倍数 //求最大公约数 Scanner in = new Scanner(System.in); int x=in.nextInt(); int y=in.nextInt(); //辗转相除法 int a=x; int b=y; int c=0; while (x%y>0) { c=x%y; x=y; y=c; } System.out.println(a*b/y); } }