Python solution with explanation
There are N number of primes from 1 to n and there are exactly N  number of prime indexes from index 1 to n. So the the number of permutations for prime numbers
There are N number of primes from 1 to n and there are exactly N  number of prime indexes from index 1 to n. So the the number of permutations for prime numbers are N! Similarly the number of permutations for nonprime numbers are (n-N)! so the total number of permutations are N!*(n-N)!\n\nFor example: from the given test case: [1,2,3,4,5]. {2, 3 and 5} are fixed on prime index slots, we can only swap them around. There are 3 x 2 x 1 = 3! ways to pick for each index slot. [[2,3,5], [2,5,3], [3,2,5], [3,5,2], [5,2,3], [5,3,2]], 2x1 for {1,4} [[1,4], [4,1]] so the total is 3!*2!\n```\nclass Solution:\n    def numPrimeArrangements(self, n: int) -> int:\n        CONST=int(math.pow(10,9))+7\n        \n        #By definition, a prime number is only divisiable by 1 and itself\n        def isPrime(num):\n            if num > 1:\n                # check for factors\n                for i in range(2,num):\n                    if (num % i) == 0:\n                        return False\n                        break\n                else:\n                    return True\n            else:\n                return False\n        \n        #Count the number of prime and non prime from 1 to n(inclusive)\n        prime=0\n        for num in range(1,n+1):\n            if isPrime(num): prime+=1\n       \n        \n        #Calculate factorial of n using dp\n        def fact(n):\n            F=[-1]*101\n            F[0]=1\n            F[1]=1\n            F[2]=2\n            if n>2:\n                F[n]=fact(n-1)*n\n            return F[n]\n        \n        return fact(prime)*fact(n-prime)%CONST\n```
[]