Marin want count number permutation beautiful a beautiful permutation length n permutation follow property gcd 1 cdot p_1 2 cdot p_2 dot n cdot p_n 1 gcd great common divisorA permutation array consist n distinct integer 1 n arbitrary order for example 23154 permutation 122 permutation 2 appear twice array 13 4 permutation n3 4 array