题目链接:1175. 质数排列
找到小于等于 $n$ 的质数数目,求其阶乘即可。
from bisect import bisect_right
from math import factorial
class Solution:
def numPrimeArrangements(self, n: int) -> int:
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
n_primes = bisect_right(primes, n)
return factorial(n_primes) * factorial(n - n_primes) % 1000000007