#P1743. Unique Paths with 17 Significant Digits

    ID: 15028 Type: Default 1000ms 256MiB

Unique Paths with 17 Significant Digits

Unique Paths with 17 Significant Digits

Given an n × m matrix, you need to calculate the number of distinct paths from the upper-left corner to the bottom-right corner. In each step you can only move either right or down. The answer should be output with exactly 17 significant digits preserved; that is, if the actual result has more than 17 digits, only the first 17 digits remain and every digit from the 18th digit onward is replaced by 0. Formally, let the exact result be represented as a string S. If len(S) > 17, then the printed output should be S[0:17] followed by (len(S)-17) zeros; otherwise, output S directly.

The mathematical formulation for the number of paths is given by the binomial coefficient \[ \binom{n+m-2}{n-1} = \frac{(n+m-2)!}{(n-1)!\,(m-1)!}. \]

inputFormat

The input consists of a single line with two positive integers n and m separated by space, representing the number of rows and columns of the matrix respectively.

n m

outputFormat

Output a single number representing the number of distinct paths with the required formatting. If the number has more than 17 digits, output the first 17 digits and replace the rest with zeros.

sample

3 3
6