#P1492. Gorilla's Walk
Gorilla's Walk
Gorilla's Walk
After a meal, the gorilla loves to take a walk on the playground. Being the most eye‐catching with its unique walk, the gorilla naturally becomes the main character of the stroll. However, as the gorilla is also quite talented in algorithmic challenges, it came up with a classic problem during the walk.
Consider an \(m \times n\) matrix. The gorilla appears at the bottom-left vertex and can only move either upward or rightward. Its goal is to reach the top-right vertex by "crawling" along the allowed paths. The challenge is to determine the total number of distinct paths available.
The answer is given by the binomial coefficient \[ C(m+n-2,\ m-1) = \frac{(m+n-2)!}{(m-1)! (n-1)!}. \]
Note: The maximum possible values for \(m\) and \(n\) are up to \(5 \times 10^4\). Although these values can lead to extremely large numbers, your program should output the exact value.
inputFormat
The input consists of a single line containing two space-separated integers \(m\) and \(n\), where \(m\) represents the number of rows and \(n\) represents the number of columns of the matrix.
outputFormat
Output the number of distinct paths from the bottom-left vertex to the top-right vertex.
sample
3 3
6