Tag: most common divisor

Java:获得最大公约数,哪种方法更好?

从这个问题Java:得到最大的公约数 获取任何数据类型的gcd是int , long , Integer , Long ,哪个答案在精度,速度,cpu使用等方面更好? A: private static int gcdThing(int a, int b) { BigInteger gcd = BigInteger.valueOf(a).gcd(BigInteger.valueOf((b))); return gcd.intValue(); } B: public int GCD(int a, int b) { return b==0 ? a : GCD(b, a%b); }