Pascal's Triangle

Interview

Time limit1sMemory limit256 MB

Summary
Given n and k with 1 <= k <= n <= 30, print the k-th entry of row n in Pascal's triangle, equal to C(n-1, k-1).
Level

Easy2 of 10

Topics
Math, Combinatorics, Implementation, Recursion
Solved
No attempts yet

Problem

Pascal's triangle arranges binomial coefficients in the shape of a triangle. It is named after Blaise Pascal (1623-1662).

In its simple form, Pascal's triangle can be built as follows.

  1. Row N has N numbers.
  2. The first row is 1.
  3. From the second row on, the two end values of each row are 1, and every other value is the sum of the two adjacent numbers in the row directly above.

For example, when n=3, the 2nd number of the 3rd row is made by adding the two adjacent numbers 1 and 1 from the row above.

When n=6, the 10 in the 6th row of Pascal's triangle is obtained by adding the two adjacent numbers 4 and 6 from the 5th row.

In the same way, when n=11, the following Pascal's triangle can be built.

Given integers n and k, write a program that prints the k-th number of the n-th row of Pascal's triangle. Note that this number is the binomial coefficient C(n−1,k−1)C(n-1,k-1).

Input

The first line gives the integers n and k in that order, separated by a space. They satisfy 1≤k≤n≤301 \le k \le n \le 30.

Output

Print the k-th number of the n-th row on the first line.

Examples2

  1. Example 1

    Input
    5 3
    
    Expected output
    6
    
  2. Example 2

    Input
    11 3
    
    Expected output
    45