对于int和long而言,作为原语,并非如此。对于Integer,有人可能写了一个。
假设BigInteger是int,Integer,long和Long的(数学/函数)超集,如果您需要使用这些类型,请将它们转换为BigInteger,执行GCD,然后将结果转换回。
private static int gcdThing(int a, int b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.intValue();}


