#P15745. [JAG 2024 Summer Camp #3] Commutativity
[JAG 2024 Summer Camp #3] Commutativity
题目描述
You are given a function $F: \{1, 2, \ldots, N\} \rightarrow \{1, 2, \ldots, N\}$. In other words, is a function that takes an integer between and inclusive and returns an integer between and inclusive. Your task is to count the number of functions $G: \{1, 2, \ldots, N\} \rightarrow \{1, 2, \ldots, N\}$ such that and commute under composition: that is, holds for any . As this number could be large, print the answer modulo .
输入格式
The input consists of a single test case of the following format.
$$\begin{aligned} & N \\ & F_{1} \ F_{2} \ \ldots \ F_{N} \end{aligned}$$The first line consists of an integer between and , inclusive. The second line consists of positive integers . For each , represents the value of . It is guaranteed that .
输出格式
Print the number of possible functions $G: \{1, 2, \ldots, N\} \rightarrow \{1, 2, \ldots, N\}$ modulo .
5
4 5 3 2 1
5
8
2 3 1 3 6 7 5 5
64
10
3 1 4 1 5 9 2 6 5 3
64
15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
567381138