#P10595. Counting Increasing Number Combinations

    ID: 12618 Type: Default 1000ms 256MiB

Counting Increasing Number Combinations

Counting Increasing Number Combinations

Xavier faces a challenging puzzle that involves selecting cards with unique positive integers. His classmate, Xerier, prepares many cards (each card bearing a distinct positive integer) and writes down an equation of the form

\( X_1 + X_2 + \cdots + X_p = n \)

Here, \( p \) indicates the number of cards to choose and \( n \) is a given target sum. In addition, the selected numbers must be in strictly increasing order:

\( X_1 < X_2 < \cdots < X_p \)

Your task is to determine the total number of valid solutions (i.e. combinations of \( p \) distinct positive integers in increasing order) that satisfy the equation. If no solution exists, output 0.

inputFormat

The input consists of two space‐separated positive integers:

  • \( p \): the number of cards (terms) to select.
  • \( n \): the target sum.

outputFormat

Output a single integer representing the number of valid solutions.

sample

3 9
3