1
/**
2
* @param {number} n
3
* @return {number}
4
*/
5

6
var findNoOfPrimes = function (n) {
7
let isPrime = new Array(n + 1).fill(true);
8

9
let count = 0;
10

11
for (let i = 2; i < n; i++) {
12
for (let j = i; j <= n; j++) {
13
isPrime[j * i] = false;
14
}
15
}
16

17
isPrime.forEach((prime) => {
18
if (prime) {
19
count++;
20
}
21
});
22

23
return count - 2;
24
};
25

26
var factorial = function (num) {
27
let modulo = Math.pow(10, 9) + 7;
28

29
if (num <= 0) return 1;
30

31
return (BigInt(num) * BigInt(factorial(num - 1))) % BigInt(modulo);
32
};
33

34
var numPrimeArrangements = function (n) {
35
let modulo = BigInt(Math.pow(10, 9) + 7);
36

37
let count = findNoOfPrimes(n);
38

39
let factorialPrime = factorial(count);
40

41
let factorialComposite = factorial(n - count);
42

43
return (BigInt(factorialPrime) * BigInt(factorialComposite)) % modulo;
44
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0