C++ Solution with Explanation
Synopsis:\n Count the primes from 1 to n inclusive\n The answer is all prime permutations multiplied by all non-prime permutations\n( ie. the factorial of the a
**Synopsis:**\n* Count the primes from 1 to n inclusive\n* The answer is all prime permutations multiplied by all non-prime permutations\n( ie. the factorial of the amount of primes multiplied by the factorial of the amount of non-primes )\n\n**Solution:**\n```\nclass Solution {\npublic:\n    constexpr static auto MOD = static_cast<int>(1e9+7);\n    int numPrimeArrangements(int n, int primes=1, long long ans=1) { // 2 is the first prime\n        for (auto i=3; i <= n; ++i) {\n            if (isPrime(i)) {\n                ++primes;\n            }\n        }\n        for (auto i=1; i <= primes; ++i) { // all permutations of primes == factorial of primes\n            ans = ans * i % MOD;\n        }\n        for (auto i=1; i <= n - primes; ++i) { // all permutations of non-primes == factorial of non-primes\n            ans = ans * i % MOD;\n        }\n        return ans;\n    }\nprivate:\n    bool isPrime(int n) {\n        for (auto i=2; i*i <= n; ++i) {\n            if (n % i == 0) {\n                return false;\n            }\n        }\n        return true;\n    }\n};\n```
[]