Permutation and combination calculator (nPr, nCr)

Calculate nCr and nPr exactly: combinations and permutations with or without repetition, for poker hands, lottery odds and PIN codes.

更新于 已验证的示例:9

试一试
Number of ways
Number of ways: 2,598,960
整数;取最近值,等距时远离零
Digits in the answer
7
Chance of one particular outcome
3.848 × 10⁻⁷

There are 2,598,960 ways to choose 5 of 52 items when order doesn't matter. If each is equally likely, any single one has a 3.848 × 10⁻⁷ chance — 1 in 2,598,960.

Size of each count for n = 52, r = 5 (number of digits, log₁₀ scale)

Combinations2,598,960Combinations (repeats)3,819,816Permutations311,875,200Permutations (repeats)380,204,032
计算方法 S
  1. Combinations

    (nr)=n!r! (n−r)!=52!5! 47!\binom{n}{r} = \frac{n!}{r!\,(n-r)!} = \frac{52!}{5!\,47!}
  2. Exact integer result

    =2,598,960= 2{,}598{,}960

    Computed in exact BigInt arithmetic.

  3. Chance of one particular outcome

    12,598,960=3.84769×10−7\frac{1}{2{,}598{,}960} = 3.84769 \times 10^{-7}

    Assumes every outcome is equally likely.

关于Permutation and combination calculator (nPr, nCr)

Combinations count the ways to pick r items from n when order doesn't matter: C(n, r) = n!/(r!(n − r)!). Permutations count each ordering separately, P(n, r) = n!/(n − r)!, so P(n, r) = C(n, r) × r!. When an item can be picked more than once, ordered picks number nʳ and unordered picks C(n + r − 1, r), the "stars and bars" count. Every answer is an exact whole number, up to 20,000 digits.

The default, 5 cards from 52, gives 2,598,960 poker hands, so one particular hand has a 1 in 2,598,960 chance. The same arithmetic gives 13,983,816 tickets in a 6-of-49 lottery, 720 podium orders from 10 runners and 10,000 four-digit PINs.

The chance of one outcome assumes every outcome is equally likely. Answers of 22 digits or more are shown in scientific notation, with every digit listed up to 300 digits.

计算示例

5-card hands from 52 (defaults)

Count
Combinations — order doesn't matter
Items to choose from (n)
52
Items chosen (r)
5
Number of ways
2,598,960
Digits in the answer
7
Chance of one particular outcome
3.848 × 10⁻⁷

核验来源:C(52,5) = 2,598,960 (Python math.comb; the standard count of poker hands)

Podium from 10 runners

Count
Permutations — order matters
Items to choose from (n)
10
Items chosen (r)
3
Number of ways
720

核验来源:10 × 9 × 8 = 720 (Python math.perm)

6 of 49 lottery

Count
Combinations — order doesn't matter
Items to choose from (n)
49
Items chosen (r)
6
Number of ways
13,983,816
Chance of one particular outcome
7.151 × 10⁻⁸

核验来源:Python math.comb(49, 6) = 13,983,816; 1/13983816 = 7.15112e-8

C(100, 50) exactly

Count
Combinations — order doesn't matter
Items to choose from (n)
100
Items chosen (r)
50
Number of ways
1.00891 × 10²⁹
Digits in the answer
30

核验来源:Python math.comb(100, 50)

常见问题

What is the difference between a permutation and a combination?

A permutation counts orderings; a combination counts only which items are chosen. From 10 runners there are P(10, 3) = 720 ways to fill gold, silver and bronze, but only C(10, 3) = 120 different groups of three, because each group can be ordered in 3! = 6 ways. Use permutations for rankings, seatings and passwords, and combinations for hands, committees and lottery tickets.

How many 5-card poker hands are there?

There are C(52, 5) = 2,598,960 five-card hands from a standard 52-card deck, counting each set of cards once regardless of the order dealt. Only 4 of them are royal flushes, so the chance of being dealt one is 4 in 2,598,960, or 1 in 649,740. Counting ordered deals instead gives P(52, 5) = 311,875,200.

How are lottery jackpot odds calculated?

Multiply the number of combinations for each drawn set. A 6-from-49 draw has C(49, 6) = 13,983,816 possible tickets. Powerball draws 5 of 69 white balls and 1 of 26 red balls, so the jackpot odds are C(69, 5) × 26 = 11,238,513 × 26, or 1 in 292,201,338. Order doesn't matter in these games, which is why combinations apply.

How many 4-digit PIN combinations are there?

There are 10⁴ = 10,000 four-digit PINs, from 0000 to 9999, because each of the 4 positions can hold any of 10 digits. Strictly this is a permutation with repetition, since 1234 and 4321 are different codes; a "combination lock" is really a permutation lock. A 6-digit PIN has 10⁶ = 1,000,000 possibilities.

Why is 0! equal to 1?

0! = 1 by definition, because there is exactly one way to arrange zero items: the empty arrangement. The convention keeps the formulas consistent, so C(n, 0) = n!/(0! × n!) = 1 and C(n, n) = 1. It also matches the gamma function, where 0! = Γ(1) = 1, and the recursion n! = n × (n − 1)! at n = 1.

“Permutation and combination calculator (nPr, nCr)”有多准确?

准确性取决于输入值和方法的假设。十进制运算使用50位有效数字,但估算、数值方法和源数据的精度可能较低;显示时的舍入并不能消除这些限制。 已按独立来源核验的计算示例:9。 例如,“5-card hands from 52 (defaults)”根据C(52,5) = 2,598,960 (Python math.comb; the standard count of poker hands)进行核验。

这种方法出自哪里?

NIST Digital Library of Mathematical Functions, §26.3 Lattice paths: binomial coefficients and §26.2 permutations; Graham, Knuth & Patashnik, Concrete Mathematics, 2nd ed., chapter 5 (binomial coefficients).

关于此计算器

(nr)=n!r!(n−r)!,P(n,r)=n!(n−r)!,(n+r−1r),nr\binom{n}{r} = \frac{n!}{r!(n-r)!},\quad P(n,r) = \frac{n!}{(n-r)!},\quad \binom{n+r-1}{r},\quad n^r

来源

  1. NIST Digital Library of Mathematical Functions, §26.3 Lattice paths: binomial coefficients and §26.2 permutations
  2. Graham, Knuth & Patashnik, Concrete Mathematics, 2nd ed., chapter 5 (binomial coefficients)

已对照来源验证

此计算器包含 9 个已解示例,答案来自独立来源。这些示例会在测试套件中运行,你也可以在此运行验证。

相关计算器