透過 MCP 連接 →

輸入計算

Constraint: n ≥ r ≥ 0. Both must be non-negative integers.

數學公式

廣告

結果

組合數(nCr)
6
ways to choose 2 from 4 (order ignored)
n(元素總數) 4
r(選取個數) 2
記法 C(4, 2)

什麼是組合計算機(nCr)?

這個計算機可以求出組合數——常寫成 nCr、C(n, r) 或「n 選 r」——也就是在不考慮選取順序的前提下,從 n 個相異元素中選出 r 個的方法總數。選到 {A, B} 與選到 {B, A} 算同一種組合。它其實就是二項式係數,是組合數學、機率與統計學裡最基礎的概念之一。

Selecting a subset of items from a larger group regardless of order
Combinations count the ways to choose r items from n distinct items when order does not matter.

使用方法

輸入元素總數 n 以及想要選取的個數 r,即可立即看到結果。兩個數值都必須是非負整數,而且 r 不能大於 n(本頁面會強制要求 \(n \ge r \ge 0\))。計算機採用大整數精確運算,即使結果非常龐大,也能維持完全準確,不會四捨五入。

公式說明

最經典的定義是 $$C(n, r) = \frac{n!}{r!\,\left(n - r\right)!}$$ 為了避免計算龐大的階乘,本工具改用穩定的連乘形式,並運用對稱性質 \(C(n, r) = C(n, n - r)\):先取 \(k = \min(r, n - r)\),從 1 開始,對 \(i = 1..k\) 逐步乘以 \((n - k + i)\) 再除以 \(i\)。由於每一次除法都剛好整除,整個過程中的數值永遠都是整數。

Advertisement
Breakdown of the n choose r formula into factorial parts
The formula divides n! by r! and (n-r)! to remove ordering of both the chosen and unchosen items.

實例演算

從 4 張牌中抽出 2 張,可以組成幾種牌組?$$C(4, 2) = \frac{4!}{2!\cdot 2!} = \frac{24}{4} = 6$$ 種。再看一個樂透的例子:從 49 個號碼中選 6 個,\(C(49, 6) = 13{,}983{,}816\) 種不同的組合——這正是頭獎中獎機率如此渺茫的原因。

Advertisement
Tree comparing ordered arrangements collapsing into unordered combinations
Several ordered arrangements (permutations) collapse into a single combination since order is ignored.

常見問題

組合與排列有什麼不同?組合不在意順序,排列則會把順序算進去。\(nPr = nCr \cdot r!\),所以在相同的 n 與 r 之下,排列數一定大於(或等於)組合數。

C(n, 0) 或 C(n, n) 是多少?兩者都等於 1:什麼都不選只有一種方式,全部都選也只有一種方式。

r 可以大於 n 嗎?不行。你無法選出比現有元素還多的數量,所以當 \(r > n\) 時 \(C(n, r) = 0\);本計算機會把這種情況視為無效並回傳 0。

最後更新: