diff --git a/src/math/big/int.go b/src/math/big/int.go index 411a56966b..29b5ddf3a5 100644 --- a/src/math/big/int.go +++ b/src/math/big/int.go @@ -206,13 +206,13 @@ func (z *Int) MulRange(a, b int64) *Int { } // Binomial sets z to the binomial coefficient C(n, k) and returns z. -func (z *Int) Binomial(n_, k_ int64) *Int { - if k_ > n_ { +func (z *Int) Binomial(n, k int64) *Int { + if k > n { return z.SetInt64(0) } // reduce the number of multiplications by reducing k - if k_ > n_-k_ { - k_ = n_ - k_ // C(n, k) == C(n, n-k) + if k > n-k { + k = n - k // C(n, k) == C(n, n-k) } // C(n, k) == n * (n-1) * ... * (n-k+1) / k * (k-1) * ... * 1 // == n * (n-1) * ... * (n-k+1) / 1 * (1+1) * ... * k @@ -235,12 +235,12 @@ func (z *Int) Binomial(n_, k_ int64) *Int { // i++ // z /= i // } - var n, k, i, t Int - n.SetInt64(n_) - k.SetInt64(k_) + var N, K, i, t Int + N.SetInt64(n) + K.SetInt64(k) z.Set(intOne) - for i.Cmp(&k) < 0 { - z.Mul(z, t.Sub(&n, &i)) + for i.Cmp(&K) < 0 { + z.Mul(z, t.Sub(&N, &i)) i.Add(&i, intOne) z.Quo(z, &i) }