Triangulation
Time limit1sMemory limit32 MB
Given n and m, compute the sum of triangulation counts T_3 + ... + T_n of convex polygons, reduced modulo m.
- Level
Medium7 of 10
- Topics
- Combinatorics, Math, Number theory, Dynamic programming
- Solved
- No attempts yet
Problem
A triangulation of a convex polygon divides its interior into triangles using diagonals that do not cross one another. The vertices are numbered from to , and two triangulations are considered different whenever their sets of diagonals differ.
For example, a pentagon can be triangulated in exactly five ways.
Let be the number of ways to triangulate a convex -gon. Write a program that computes .
Input
The first line contains two integers and , separated by a space. (, )
Output
Print the remainder of divided by .