Skip to main content
Back to problems
Codeforces
Easy
Combinatorics
Math
Combination

Compute the number of ways to choose mm items from nn distinct items.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Combination

Given two integers nn and mm, determine how many different groups of size mm can be formed from nn distinct items.

This is the standard combination count, often written as C(n,m)C(n,m) or (nm){n \choose m}.

You may assume the inputs are valid and fit in normal integer ranges for the intended solution approach.

Input Format

  • Two integers nn and mm.
  • They represent the total number of distinct items and the size of the group to choose.

Output Format

  • Print a single integer: the number of ways to choose exactly mm items from nn distinct items.

Constraints

  • 0≤m≤n0 \le m \le n
  • nn is small enough that the result fits in the expected integer type for the problem setting.
Examples
Sample cases returned by the problem API.

Example 1

Input

5 2

Output

10

Explanation

There are (52)=10\binom{5}{2} = 10 ways to choose 2 items from 5 distinct items.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.