100% runtime, factorial, counting prime and non prime
\nPLEASE UPVOTE IF YOU LIKE.\n\n\tpublic int numPrimeArrangements(int n) {\n        \n        int mod = (int) (Math.pow(10,9) + 7);\n        boolean[] arr=new b
```\nPLEASE UPVOTE IF YOU LIKE.\n```\n\tpublic int numPrimeArrangements(int n) {\n        \n        int mod = (int) (Math.pow(10,9) + 7);\n        boolean[] arr=new boolean[n+1];\n        int cntNonPrm = 1;\n        \n        for (int i = 2; i * i <= n; i++) {\n            for (int j = i * 2; j <= n; j += i) {\n                if(!arr[j]) {\n                    arr[j]=true;\n                    cntNonPrm++;\n                }\n            }\n        }\n\n        int cntPrm = n-cntNonPrm;\n        long sum = 1;\n\n        for (int i = 1; i <= Math.max(cntPrm, cntNonPrm) ; i++) {\n            if (i <= Math.min(cntPrm, cntNonPrm)){\n                sum *= ((long) i * i );\n                sum %= mod;\n            }\n            else {\n                sum *= i;\n                sum %= mod;\n            }\n        }\n\n        return (int) sum;\n    }
['Java']