Java sum of permutations of primes and non-primes
We count the number of primes <= n.\nThe total number of arragements = total number of permutations of primes + total number of permutations of non-primes\n\n\n
We count the number of primes `<= n`.\nThe total number of arragements = total number of permutations of primes + total number of permutations of non-primes\n\n```\nclass Solution {\n    public int numPrimeArrangements(int n) {\n        int m = countPrimes(n+1), M = 1000000007;\n        long count = 1;\n        for (int i = m; i > 0; i--) {\n            count = (count*i)%M;\n        }\n        for (int i = n-m; i > 0; i--) {\n            count = (count*i)%M;\n        }\n        return (int)count;\n    }\n    \n    private int countPrimes(int n) {\n        boolean[] isPrime = new boolean[n];\n        for (int i = 2; i < n; i++) {\n            isPrime[i] = true;\n        }\n        \n        for (int i = 2; i*i < n; i++) {\n            if (!isPrime[i]) {\n                continue;\n            }\n            for (int j = i*i; j < n; j += i) {\n                isPrime[j] = false;\n            }\n        }\n        \n        int count = 0;\n        for (int i = 2; i < n; i++) {\n            if (isPrime[i]) {\n                count++;\n            }\n        }\n        return count;\n    }\n}\n```
[]