C++ solution 100% faster
\nclass Solution {\npublic:\n    int tot_primes(int n){\n        int i,j,tot=2;\n        bool fu;\n        for(i=4; i<=n; i++){\n            fu=true;\n         
```\nclass Solution {\npublic:\n    int tot_primes(int n){\n        int i,j,tot=2;\n        bool fu;\n        for(i=4; i<=n; i++){\n            fu=true;\n            for(j=2; j<=int(sqrt(i)); j++){\n                if(i%j==0){\n                    fu=false;\n                    break;\n                }\n\n            }\n            if(fu)\n                tot++;\n        }\n            return tot;\n}\n    int numPrimeArrangements(int n) {\n           if(n<=2)\n               return 1;\n           else if(n==3)\n               return 2;\n           long long unsigned int p=1;\n           int nu=tot_primes(n),i;\n           for(i=2; i<=nu; i++){\n               p*=i;\n               if(p>int(pow(10,9)+7))\n                   p%=int(pow(10,9)+7);\n           }\n           for(i=2; i<=n-nu; i++){\n               p*=i;\n               if(p>int(pow(10,9)+7))\n                   p%=int(pow(10,9)+7);\n           }\n        return p;\n    }\n};\n```
[]