QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 128 MB مجموع النقاط: 100

#12671. Spanning Tree Counting

الإحصائيات

Recently, Xiaodong has made amazing progress in calculating the number of spanning trees of undirected connected graphs. He discovered: The number of spanning trees of a cycle with $n$ nodes is $n$. The number of spanning trees of a complete graph with $n$ nodes is $n^{n-2}$.

These two discoveries thrilled Xiaodong, strengthening his resolve to continue calculating the number of spanning trees for various types of graphs.

One day, at a gathering with his classmates, everyone sat around a large round table. Xiaodong immediately thought of the spanning tree problem. If each classmate is considered a node and an edge is connected between neighbors (distance between nodes is 1), it becomes a cycle. However, Xiaodong was already very familiar with counting cycles and was no longer interested. So, Xiaodong modified the graph: not only is an edge connected between neighbors, but an edge is also connected between classmates sitting one seat apart (distance between nodes is 2). These two cases where nodes are directly connected by an edge are collectively referred to as being connected by an edge, as shown in Figure 1.

Figure 1

Xiaodong had not calculated the number of spanning trees for this type of graph before, but he remembered a general method for calculating the number of spanning trees of any graph taught by his teacher: construct an $n \times n$ matrix $A = \{a_{ij}\}$ where:

$$a_{ij} = \begin{cases} d_i & i = j \\ -1 & i \text{ and } j \text{ are connected by an edge} \\ 0 & \text{otherwise} \end{cases}$$

where $d_i$ represents the degree of node $i$.

The matrix $A$ corresponding to Figure 1 is shown below. To calculate the number of spanning trees corresponding to Figure 1, simply remove the last row and last column of matrix $A$ to obtain an $(n-1) \times (n-1)$ matrix $B$. The value of the determinant of matrix $B$ gives the number of spanning trees for Figure 1.

Xiaodong found that using the general method was too complex to calculate, and it was difficult to find a simpler formula using other methods. Therefore, he simplified the graph by breaking the round table at one point, so that all classmates formed a chain, with connections between nodes at distance 1 and distance 2. For example, the case for eight points is as follows:

The total number of spanning trees decreased significantly. Xiaodong kept thinking until the gathering ended and finally found a quick way to calculate the number of spanning trees for this graph. However, if points at distance 3 were also connected, Xiaodong would not know how to calculate it quickly. Now, please help Xiaodong calculate the number of spanning trees for this type of graph.

Input

The input contains two integers $k$ and $n$, separated by a space. $k$ indicates that all nodes with a distance of at most $k$ (inclusive) are connected, and $n$ indicates that there are $n$ nodes.

Output

Output a single integer representing the number of spanning trees. Since the answer may be large, you only need to output the remainder of the answer divided by 65521.

Examples

Input 1

3 5

Output 1

75

Note

The graph corresponding to the example is as follows:

$$A = \begin{bmatrix} 3 & -1 & -1 & -1 & 0 \\ -1 & 4 & -1 & -1 & -1 \\ -1 & -1 & 4 & -1 & -1 \\ -1 & -1 & -1 & 4 & -1 \\ 0 & -1 & -1 & -1 & 3 \end{bmatrix}, B = \begin{bmatrix} 3 & -1 & -1 & -1 \\ -1 & 4 & -1 & -1 \\ -1 & -1 & 4 & -1 \\ -1 & -1 & -1 & 4 \end{bmatrix}, |B| = 75$$

Constraints

For all data, $2 \le k \le n$.

Data ID $k$ Range $n$ Range Data ID $k$ Range $n$ Range
1 $k=2$ $n \le 10$ 6 $k \le 5$ $n \le 100$
2 $k=3$ $n=5$ 7 $k \le 3$ $n \le 2000$
3 $k=4$ $n \le 10$ 8 $k \le 5$ $n \le 10000$
4 $k=5$ $n=10$ 9 $k \le 3$ $n \le 10^{15}$
5 $k \le 3$ $n \le 100$ 10 $k \le 5$ $n \le 10^{15}$

Hint

One method to calculate a determinant: let $\alpha(P)$ be the number of inversions in a permutation $P$, then the determinant of $B$ is:

$$|B| = \sum_{P=p_1p_2\dots p_n \in S_n} (-1)^{\alpha(P)} \prod_{j=1}^{n} b_{j, p_j}$$

For example, if $B = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 0 \end{bmatrix}$, the calculation is as follows:

$P$ $\alpha(P)$ $b_{1, p_1}$ $b_{2, p_2}$ $b_{3, p_3}$ $(-1)^{\alpha(P)} \prod_{j=1}^{n} b_{j, p_j}$
1 2 3 0 1 5 0 0
1 3 2 1 1 6 8 -48
2 1 3 1 2 4 0 0
2 3 1 2 2 6 7 84
3 1 2 2 3 4 8 96
3 2 1 3 3 5 7 -105

Thus, the determinant of $B$ is $0 - 48 + 0 + 84 + 96 - 105 = 27$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.