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 void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int m = cin.nextInt();
int n = cin.nextInt();
System.out.println (gcd (m, n));
}
}