Python 3 + explanation. Faster than 79.7%, less memory than 100%
This problem can be restated as counting the number of ways we can permute the prime numbers and the non prime numbers.\nThere are n! ways to permute n objects.
This problem can be restated as counting the number of ways we can permute the prime numbers and the non prime numbers.\nThere are n! ways to permute n objects. So we will have prime_numbers! ways to permute the prime numbers and non_prime! ways\nto permute the non_prime numbers and then we multiply those two to find the total. The problem is reduced to finding the number\nof the prime numbers between 1 to n.\n\n```\nclass Solution:\n    def prime_numbers(self, n):\n        primes = 0\n        is_prime = True\n        for number in range(2, n+1):\n            for i in range(2, number):\n                if number % i == 0:\n                    is_prime = False\n                    break\n            if is_prime:\n                primes += 1\n            is_prime = True\n        return primes\n\n    def factorial(self, n):\n        from functools import reduce\n        from operator import mul\n        return reduce(mul, range(1,n+1), 1)\n    \n    def numPrimeArrangements(self, n: int) -> int:\n        prime_count = self.prime_numbers(n)\n        non_prime_count = n - prime_count\n        return (self.factorial(prime_count) * self.factorial(non_prime_count)) % (10**9 + 7)\n```
[]