Fractal Sequence
InterviewTime limit1sMemory limit1024 MB
Count the sequences A of N distinct positive integers whose sorted version B satisfies the fixed-point condition, printed modulo M.
- Level
Medium4 of 10
- Topics
- Math, Combinatorics
- Solved
- No attempts yet
Problem
There is a sequence of distinct positive integers. Let be the sequence obtained by sorting in ascending order. Using , define a sequence of length as follows.
Here, for every with , is the -th element of , and is the -th element of .
A sequence is called a fractal sequence if . Given and , find the number of distinct fractal sequences of length , modulo .
Input
The first line contains two integers () and (), separated by a space.
Output
Print the number of distinct fractal sequences of length , modulo .
Hint
Two sequences and are equal if and only if the following holds.
- and have the same length.
- If that length is , then for every with , the -th element of equals the -th element of .
If two sequences and are equal, this is written as .