1175. Prime Arrangements
On This Page
class Solution:
def numPrimeArrangements(self, n: int) -> int:
def count(n):
cnt = 0
primes = [True] * (n + 1)
for i in range(2, n + 1):
if primes[i]:
cnt += 1
for j in range(i + i, n + 1, i):
primes[j] = False
return cnt
cnt = count(n)
res = factorial(cnt) * factorial(n - cnt)
return res % (10**9 + 7)