Mar*_*arl 5 java greatest-common-divisor
从这个问题Java:得到最大公约数
在获取任何数据类型的 gcd 时,无论是int, long, Integer, Long,哪个答案在精度、速度、cpu 使用率等方面更好?
A:
private static int gcdThing(int a, int b) {
return BigInteger.valueOf(a).gcd(BigInteger.valueOf((b))).intValue();
}
Run Code Online (Sandbox Code Playgroud)
乙:
public int GCD(int a, int b) { return b==0 ? a : GCD(b, a%b); }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1185 次 |
| 最近记录: |