#K53382. Permutation Order
Permutation Order
Permutation Order
Problem Statement:
You are given a permutation (h) of the integers (1) to (n). The order of the permutation is defined as the smallest positive integer (m) such that when the permutation is applied (m) times, the result is the identity permutation. Mathematically, if (h^{m}) equals the identity permutation, then (m) is the order of (h).
Hint: The order of a permutation is equal to the least common multiple ((\mathrm{lcm})) of the lengths of its disjoint cycles.
inputFormat
Input is read from standard input (stdin).
The first line contains an integer (n), the number of elements in the permutation.
The second line contains (n) space-separated integers representing the permutation (h).
outputFormat
Output the order of the permutation to standard output (stdout).## sample
4
2 3 4 1
4