一个简单的小算法来获取两个数的最大公约数,
1 public class Test { 2 public static void main(String[] args) { 3 long result = gcd(15, 3); 4 System.out.println(result); 5 } 6 7 public static long gcd(long m, long n) { 8 while (n != 0) { 9 long rem = m % n; 10 m = n; 11 n = rem; 12 } 13 return m; 14 15 } 16 }