✅ Sieve || 100% faster
c++\nclass Solution {\n    int mod = 1e9 + 7;\npublic:\n    int numPrimeArrangements(int n, int primeCount = 0, long long res = 1) {\n        vector<int> prime(
```c++\nclass Solution {\n    int mod = 1e9 + 7;\npublic:\n    int numPrimeArrangements(int n, int primeCount = 0, long long res = 1) {\n        vector<int> prime(n + 1, true);\n        prime[0] = false; prime[1] = false;\n        for (auto i = 2; i * i <= n; i++)\n            if (prime[i])\n                for (auto factor = 2; i * factor <= n; factor++) \n                    prime[i * factor] = false;\n        for (auto val: prime) if (val) primeCount++;\n        for (auto i = 1; i <= primeCount; i++) res = (res * i) % mod;\n        for (auto i = 1; i <= n - primeCount; i++) res = (res * i) % mod;\n        return res;\n    }\n};\n```\n\n**For more solutions, check out this \uD83C\uDFC6  [GITHUB REPOSITORY](https://github.com/MuhtasimTanmoy/playground) with over 1500+ solutions.**
[]