JavaScript Solution with Sieve of Eratosthenes
javascript\n/**\n * @param {number} n\n * @return {number}\n */\nvar numPrimeArrangements = function(n) {\n  const primes = countPrimes(n);\n  return (factorial
```javascript\n/**\n * @param {number} n\n * @return {number}\n */\nvar numPrimeArrangements = function(n) {\n  const primes = countPrimes(n);\n  return (factorial(primes) * factorial(n - primes)) % 1000000007n;\n};\n\n// return factorial after modulo operation\nconst factorial = n =>\n  n <= 1 ? 1n : (BigInt(n) * factorial(n - 1)) % 1000000007n;\n\n// return number of primes within [1,n]\nconst countPrimes = function(n) {\n  const nums = [...Array(n + 1).keys()].slice(2);\n  for (let i = 0; i <= Math.floor(Math.sqrt(n)); i++) {\n    if (nums[i]) {\n      for (let j = i + nums[i]; j <= n; j += nums[i]) {\n        nums[j] = undefined; // Sieve of Eratosthenes\n      }\n    }\n  }\n  return nums.filter(n => n).length;\n};\n```\n\n* 100/100 cases passed (44 ms)\n* Your runtime beats 100 % of javascript submissions\n* Your memory usage beats 100 % of javascript submissions (35.3 MB)
['JavaScript']