UtilityToolsLab

© 2026 UtilityToolsLab. Built and maintained by the UtilityToolsLab Team.

Free eBooks·About·Changelog·Privacy Policy·Terms of Service·Report a bug
HomeCompetitive ProgrammingCombinatorics

Related Tools

Code FormatterMatrix GeneratorComplexity CalcBit VisualizerBitmask PlannerPrime FactorsMEX CalcInterval MergerMatrix RotationPBDS GeneratorSegment TreeGraph VisualizerStress TesterModulo CalcConvex HullPath FinderOffline JudgeBig-O AnalyzerDP Table BuilderExtended GCDSieve VisualizerBinary SearchSorting VisualizerSparse Table RMQUnion-Find DSU

Combinatorics Calculator

Calculate nCr, nPr, factorials, Catalan numbers and Stirling numbers using exact BigInt arithmetic. Step-by-step working shown for every result.

You Might Also Like

All Competitive Programming

Scientific Calculator

Solve trig, log, power and factorial expressions with a full scientific keypad, DEG/RAD modes, memory keys, and calculation history. No eval() used.

Code Formatter

Format and beautify C++, Java, and Python code with consistent indentation. 100% client-side — no code leaves your browser.

Matrix Generator

Generate grid/matrix inputs for competitive programming. Random, zeros, identity, or sequential fill. Outputs in multiple formats.

Complexity Calc

Estimate Big-O operations and runtime for any N. Interactive reference table for all complexity classes from O(1) to O(N!).

Counting problems look simple on the surface — how many ways to choose 3 items from 10, how many ways to arrange 5 letters — until you need the answer quickly, the numbers get large, or the question becomes "how many ways to partition a set into non-empty subsets". Combinatorics Calculator handles five of the most common counting formulas, computes exact results using arbitrary-precision integers, and shows every step of the working so you can follow the derivation rather than just trust the answer.

Five modes cover the full range of undergraduate and competitive programming counting problems. nCr (combinations) counts unordered selections. nPr (permutations) counts ordered arrangements. Factorial computes n! directly. Catalan numbers count balanced parentheses, binary trees and polygon triangulations. Stirling numbers of the second kind count partitions of an n-element set into k non-empty subsets.

Worked Example: Choosing a Committee of Three From Ten

Click Load Sample in nCr mode to set n = 10 and r = 3. The result is 120. The working panel shows:

  • C(n, r) = n! / (r! × (n − r)!)
  • C(10, 3) = 10! / (3! × 7!) = 120
  • Switch to nPr with the same values and the answer becomes 720 — that is 120 × 6, because each combination of 3 can be arranged in 3! = 6 ways.
  • Switch to Catalan(n) with n = 7 to get 429, the number of ways to fully parenthesize 8 factors, triangulate a 9-gon, or stack 7 pairs of brackets.
  • S(n, k) mode with n = 5, k = 3 gives 25 — the number of ways to partition a 5-element set into exactly 3 non-empty subsets. This is the mode most visitors miss on the first visit.

The Five Formulas, Written Out

  • C(n, r) = n! / (r! × (n − r)!). Computed by cancelling common factors incrementally rather than evaluating three full factorials, so the intermediate values stay small even when n approaches 1,000.
  • P(n, r) = n! / (n − r)! = n × (n−1) × … × (n−r+1). The product of r consecutive integers starting at n.
  • n! is the product of all integers from 1 to n. Capped at 500. That size (500!) has 1,135 digits and renders visibly; 1,000! would freeze the output panel.
  • Catalan(n) = C(2n, n) / (n + 1). Computed from nCr rather than the recurrence, so it scales to n = 1,000 without stack overflow.
  • S(n, k) = (1/k!) × Σ (−1)^(k−j) × C(k,j) × jⁿ. The alternating sum uses BigInt throughout so the signed intermediate values never lose precision.

Precision, Rounding and the Ceiling at n = 1 000

  • All five modes use JavaScript BigInt for exact integer arithmetic with no floating-point rounding. C(1000, 500) has 299 digits and is computed exactly.
  • Results longer than 40 digits are shown in the form XXXXXX...XXXXXX (N digits) to keep the layout intact. The Copy button copies the full untruncated value.
  • n is capped at 1,000. Inputs above that limit show n is capped at 1000 to prevent browser hang. Factorial is additionally capped at 500 because its output is rendered in full.
  • r must not exceed n for nCr and nPr. An r > n input shows r cannot exceed n for combinations (or permutations). Mathematically, C(n, r) = 0 for r > n, but the error is shown rather than silently returning 0 to avoid confusion.

Enter values above, or hit Load Sample to compute C(10, 3) = 120.