Advertisement
kosievdmerwe

Untitled

Sep 14th, 2022
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. PRIMES = [
  2.     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
  3. ]
  4. MOD = 10**9 + 7
  5.  
  6. def calc_num_primes(n: int) -> int:
  7.     return len([p for p in PRIMES if p <= n])
  8. def factorial(n):
  9.     ans = 1
  10.     for i in range(1, n + 1):
  11.         ans *= i
  12.         ans %= MOD
  13.     return ans
  14.  
  15. class Solution:
  16.     def numPrimeArrangements(self, n: int) -> int:
  17.         return (
  18.             lambda n, num_primes, factorial: factorial(num_primes) * factorial(n - num_primes) % MOD
  19.         )(
  20.             n,
  21.             calc_num_primes(n),
  22.             factorial
  23.         )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement