Python - the sieve of Eratosthenes
\nclass Solution:\n    def numPrimeArrangements(self, n: int) -> int:\n        def sieveOfEratosthenes(n):\n            primes = [1] * (n + 1)\n            for 
```\nclass Solution:\n    def numPrimeArrangements(self, n: int) -> int:\n        def sieveOfEratosthenes(n):\n            primes = [1] * (n + 1)\n            for i in range(2, int(math.sqrt(n))+1):\n                if primes[i]:\n                    primes[i*i:n+1:i] = [0] * len(primes[i*i:n+1:i])            \n            return sum(primes) - 2\n        \n        count = sieveOfEratosthenes(n)        \n        return math.factorial(n-count) * math.factorial(count) % (10**9 + 7)\n```
['Python', 'Python3']