Simple java code 0 ms beats 100 %
\n# Complexity\n- \n\n# Code\n\nclass Solution {\n    int mod=(int)1e9 +7;\n    public boolean check(int n){\n        if(n==2){\n            return true;\n     
\n# Complexity\n- \n![image.png](https://assets.leetcode.com/users/images/439423c0-6e3e-48c2-9ff8-91661e1e4601_1704769182.8242888.png)\n# Code\n```\nclass Solution {\n    int mod=(int)1e9 +7;\n    public boolean check(int n){\n        if(n==2){\n            return true;\n        }\n        else if(n%2==0){\n            return false;\n        }\n        int len=(int)Math.sqrt(n);\n        for(int i=3;i<=len;i+=2){\n            if(n%i==0){\n                return false;\n            }\n        }\n        return true;\n    }\n    public long fact(int n){\n        long mul=1;\n        for(int i=2;i<=n;i++){\n            mul=(mul*i)%mod;\n        }\n        return mul;\n    }\n    public int numPrimeArrangements(int n) {\n        int count=0;\n        for(int i=2;i<=n;i++){\n            if(check(i)){\n                count++;\n            }\n        }\n        int x=n-count;\n        long f1=fact(count)%mod;\n        long f2=fact(x)%mod;\n        return (int)((f1*f2)%mod);\n    }\n}\n```
['Java']