JavaScript Answer passed, but have a number precision issue?
I came up with the following code during contest: \n\n/**\n * @param {number} n\n * @return {number}\n */\nvar numPrimeArrangements = function(n) {\n    let how
I came up with the following code during contest: \n```\n/**\n * @param {number} n\n * @return {number}\n */\nvar numPrimeArrangements = function(n) {\n    let howManyPrime = 0;\n    let primes = 1;\n    let nonePrimes = 1;\n    for (let i = 1; i <= n; i++) {\n        howManyPrime = isPrime(i) ? ++howManyPrime : howManyPrime;\n    }\n    for (let i = howManyPrime; i >= 1; i--) {\n        primes = i * primes % (10**9 + 7);\n    }\n    for (let i = n - howManyPrime; i >= 1; i--) {\n        nonePrimes = i * nonePrimes % (10**9 + 7);\n    }\n    let result = primes * nonePrimes % (10**9 + 7);\n    return result;\n};\n\nfunction isPrime(value) {\n    for(var i = 2; i < value; i++) {\n        if(value % i === 0) {\n            return false;\n        }\n    }\n    return value > 1;\n}\n```\n\nHowever the answer is not right, but very close, like for `input=100`, correct answer should be `682289015` my answer is `682289019`\n\nSo I tweaked my logic a little bit:\n```\n/**\n * @param {number} n\n * @return {number}\n */\nvar numPrimeArrangements = function(n) {\n    let howManyPrime = 0;\n    let primes = 1;\n    let nonePrimes = 1;\n    for (let i = 1; i <= n; i++) {\n        howManyPrime = isPrime(i) ? ++howManyPrime : howManyPrime;\n    }\n    console.log(howManyPrime);\n    for (let i = howManyPrime; i >= 1; i--) {\n        primes = i * primes % (10**9 + 7);\n    }\n    for (let i = n - howManyPrime; i >= 1; i--) {\n\t// !!!! Here is the change;\n        primes = i * primes % (10**9 + 7);\n    }\n    return primes;\n};\n\nfunction isPrime(value) {\n    for(var i = 2; i < value; i++) {\n        if(value % i === 0) {\n            return false;\n        }\n    }\n    return value > 1;\n}\n\n```\nInstead doing facotial twice, I continued to do mutiplication on the existing `primes` and the answer is correct and passed tests\n\nSo the logic is totally the same. but one is wrong, the other is right. My guess is something is wrong with JS\'s big number precision, but I don\'t know exactly what went wrong. Anyone has idea? Thanks!
[]