Python solution | Sieve of Eratosthenes and simple combinatorics
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nfrom math import factorial\n\nclass Solution:\n    def countPrimes(self, n: int) -> int:\n\n        isPrime = [True] * (n + 1)\n        d = 2\n        while d * d <= n:\n            if isPrime[d]:\n                for i in range(d ** 2, n + 1, d):\n                    isPrime[i] = False\n            d += 1\n\n        x = len([x for x in isPrime[2:n] if x])\n\n        return x\n\n    def numPrimeArrangements(self, n: int) -> int:\n\n        return factorial(self.countPrimes(n + 1)) * factorial(n - self.countPrimes(n + 1)) % (10**9 + 7)\n        \n```
['Python3']