<p>Return the number of permutations of 1 to <code>n</code> so that prime numbers are at prime indices (1-indexed.)</p>

<p><em>(Recall that an integer&nbsp;is prime if and only if it is greater than 1, and cannot be written as a product of two positive integers&nbsp;both smaller than it.)</em></p>

<p>Since the answer may be large, return the answer <strong>modulo <code>10^9 + 7</code></strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 5
<strong>Output:</strong> 12
<strong>Explanation:</strong> For example [1,2,5,4,3] is a valid permutation, but [5,2,3,4,1] is not because the prime number 5 is at index 1.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 100
<strong>Output:</strong> 682289015
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 100</code></li>
</ul>

class Solution:
  def numPrimeArrangements(self, n: int) -> int:
    MOD = 10 ** 9 + 7

    def findPrimes(n: int):
      # Init numbers[0] and numbers[1] as False because 0 and 1 are not prime.
      # Init numbers[2] through numbers[n-1] as True because we assume each number
      # is prime until we find a prime number (p) that is a divisor of the number
      numbers = [False if i < 2 else True for i in range(n + 1)]
      for p in range(2, int(math.sqrt(n)) + 1):
        if not numbers[p]:
          continue
        # Set all multiples of p to false because they are not prime.
        for multiple in range(p * p, n + 1, p):
          numbers[multiple] = False

      # numbers[index] will only be true where index is a prime number
      # return the number of indices whose value is true.
      return numbers

    def factorial(num):
      f = 1
      for i in range(2, num + 1):
        f = (f * i) % MOD
      return f

    primes = findPrimes(n)
    primes_count = sum(1 if primes[x] else 0 for x in range(1, n + 1))
    non_primes_count = n - primes_count
    return factorial(primes_count) * factorial(non_primes_count) % MOD
29