This commit is contained in:
Looly 2025-11-26 20:04:48 +08:00
parent b8908cf3ef
commit ea717843f6

View File

@ -57,8 +57,8 @@ public class Combination implements Serializable {
* 1. 利用对称性 m = min(m, n-m) * 1. 利用对称性 m = min(m, n-m)
* 2. 每一步先乘 BigInteger再除以当前 i保证数值不暴涨 * 2. 每一步先乘 BigInteger再除以当前 i保证数值不暴涨
* *
* @param n 总数 n必须 >= 0 * @param n 总数 n必须 大于等于 0
* @param m 取出 m必须 >= 0 * @param m 取出 m必须 大于等于 0
* @return C(n, m) BigInteger 精确值 m > n 时返回 BigInteger.ZERO * @return C(n, m) BigInteger 精确值 m > n 时返回 BigInteger.ZERO
*/ */
public static BigInteger countBig(int n, int m) { public static BigInteger countBig(int n, int m) {
@ -87,9 +87,10 @@ public class Combination implements Serializable {
/** /**
* 安全组合数 long 版本 * 安全组合数 long 版本
* *
* @param n 总数 n必须 >= 0 * @param n 总数 n必须 大于等于 0
* @param m 取出 m必须 >= 0 * @param m 取出 m必须 大于等于 0
* <p>若结果超出 long 范围会抛 ArithmeticException而非溢出</p> * <p>若结果超出 long 范围会抛 ArithmeticException而非溢出</p>
* @return C(n, m) long 精确值 m 大于 n 时返回 0L
*/ */
public static long countSafe(int n, int m) { public static long countSafe(int n, int m) {
BigInteger big = countBig(n, m); BigInteger big = countBig(n, m);