Skip to content

Instantly share code, notes, and snippets.

@devetude
Created September 22, 2016 14:59
Show Gist options
  • Save devetude/2dedc0371f2dc1788828c9458a4a6c8a to your computer and use it in GitHub Desktop.
Save devetude/2dedc0371f2dc1788828c9458a4a6c8a to your computer and use it in GitHub Desktop.
유클리드 최대공약수를 이용한 최소공배수 알고리즘 (Euclid LCM By Using GCD)
import java.util.Scanner;
/**
* 유클리드 최대공약수를 이용한 최소공배수 알고리즘 (Euclid LCM By Using GCD)
*
* @author devetue
*/
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
sc.close();
int gcd = 0;
int multiplyAB = a * b;
while (true) {
if (b == 0) {
gcd = a;
break;
}
int tmp = b;
b = a % b;
a = tmp;
}
System.out.println(multiplyAB / gcd);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment