Hongmu Notes

Calculation of factorials and combinations of large numbers

The calculation of factorials of large numbers and combined numbers solves the problem of accuracy: ordinary calculators lose accuracy after n is set to 21, but this tool uses large integers to calculate accurately until n is 1000.
100% Browser local processing 0 Data upload

🎲 Factorials, permutations and combinations

💡 Instructions for use

  • If only n is filled in and r is not filled in, only the factorial is output; if both are filled in, the number of permutations and combinations will be given at the same time, which is suitable for checking together.
  • The input is calculated precisely with large integers: the factorial of 1000 has over two thousand digits, without scientific notation or loss of precision.
  • The result area will automatically check two identities: the factorial of the combination number multiplied by r is equal to the permutation number; C(n,r) is equal to C(n,n-r).
  • r must not be greater than n, otherwise the input error will be prompted; when n is 0, the factorial is 1, which conforms to mathematical conventions.

The calculation of factorials of large numbers and combined numbers solves the problem of accuracy: ordinary calculators lose accuracy after n is set to 21, but this tool uses large integers to calculate accurately until n is 1000.

Why floating point is not enough

Double-precision floating point can only accurately represent about fifteen or sixteen significant digits, and the factorial of 21 already has twenty digits, and every digit after that is rounded off. Continue to increase n, and the output will become scientific notation, or even directly displayed as infinity. To do consecutive multiplications and divisions on integers, you must use arbitrary-precision integers, which is how this tool is implemented.

Scale reference

numerical valueResult digits
50! 65
100!158
500!1135
1000!2568

The complete numbers of the results are very long, and the tool will also give the number of digits to make it easier to judge whether they are consistent with expectations; it is recommended to download them as text when you need to save them.

When the values are very large, term-by-term multiplication quickly exceeds normal precision, and the result ends up with a string of zeros or becomes scientific notation. In this case, large integer arithmetic should be used, or logarithms should be used to estimate magnitudes instead.

When estimating the magnitude, you can use Stirling approximation and replace the factorial with a combination of exponents and powers. You can determine the approximate number of digits in the result in a few seconds, which is more suitable for feasibility judgment than precise calculation.

When estimating the magnitude, use logarithms or approximate formulas to determine feasibility in a few seconds; when precise values are required, calculations should be performed by tools that support large integers.

When n is set to 1000, the result will exceed 2,000 digits. It is more reliable to check after copying or downloading.

📖 Glossary

factorial
The continuous product from 1 to n, written n!, stipulates that 0! is equal to 1.
arrange
Take r elements from n different elements and arrange them in a column in order. Different results will be calculated in different orders.
combination
Select r elements from n different elements, only looking at which ones are selected, not the order.
Number of permutations A(n,r)
The number of permutations is equal to the factorial of n divided by the factorial of (n-r), which can also be written as the multiplication of r consecutive numbers starting from n.
Number of combinations C(n,r)
The number of combinations is equal to the factorial of n divided by the factorial of r and the factorial of (n-r), often written as a binomial coefficient.
Symmetry
The number of combinations satisfies C(n,r) = C(n,n-r): there is a one-to-one correspondence between selecting r and leaving n-r.
recursion formula
C(n,r) = C(n-1,r-1) + C(n-1,r), which is the generation rule of Yang Hui's triangle.
Yang Hui triangle
A triangular number table obtained by arranging the combination numbers in n rows. The two ends of each row are 1, and the middle is the sum of the two numbers above.
Full arrangement
The arrangement when r is equal to n, the number of species is the factorial of n, represents the number of options to queue all elements.
large integer
An integer outside the range of ordinary floating point precision. The factorial grows extremely fast, and starting from n 21 is beyond the range that can be accurately represented by double precision.

🔗 All keywords and tutorials

Keywords page of the tool12a

Return to tool home page

❓ FAQ

Why is the factorial of 21 inexact??
Because 21! is a twenty-digit integer, exceeding the sixteen-digit upper limit that double-precision floating point can accurately represent, the subsequent results can only be approximate values.
Can you calculate the factorial of ten thousand??
The upper limit of this tool is 1000, at which point the result exceeds 2500 digits; for larger values, it is recommended to use a specialized arbitrary precision calculation tool.