Skip to content

Instantly share code, notes, and snippets.

@devetude
Last active September 22, 2016 14:48
Show Gist options
  • Save devetude/87d3c26c127e101e82c7579e74a467cf to your computer and use it in GitHub Desktop.
Save devetude/87d3c26c127e101e82c7579e74a467cf to your computer and use it in GitHub Desktop.
유클리드 최대공약수 알고리즘 1 (Euclid GCM 1)
import java.util.Scanner;
/**
* 유클리드 최대공약수 알고리즘 1 (Euclid GCD 1)
*
* @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();
while (true) {
if (b == 0) {
System.out.println(a);
break;
}
else if (a > b) {
a -= b;
}
else {
int tmp = a;
a = b - a;
b = tmp;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment