Java BigInteger Solution only one time mod required
Same as prime and non-prime number count idea, e.g in 1 to 5, we have 2, 3, 5 as 3 prime numbers, and 1, 4 as non-prime number, and prime numbers only should so
Same as prime and non-prime number count idea, e.g in 1 to 5, we have 2, 3, 5 as 3 prime numbers, and 1, 4 as non-prime number, and prime numbers only should sort with prime numbers, non-prime numbers should only sort with non-prime numbers, so combinations should be 3! * 2! = 12, same for 100, we will have 25 prime numbers and 75 non-prime numbers, combinations should be 25! * 75!\ninstead of using long, use BigInteger only need to MOD once\n```\nimport java.math.BigInteger;\nclass Solution {\n    public int numPrimeArrangements(int n) {\n        if(n == 1) {\n            return 1;\n        }\n        int primeNum = 0;\n        for(int i = 2; i <= n; i++) {\n            if(isPrime(i)) {\n                primeNum++;\n            }\n        }\n        int nonPrimeNum = n - primeNum;\n        BigInteger a = totalComb(primeNum);\n        BigInteger b = totalComb(nonPrimeNum);\n        BigInteger result = a.multiply(b);\n        BigInteger MOD = BigInteger.valueOf(1000000007);\n        return result.mod(MOD).intValue();\n    }\n    \n    private BigInteger totalComb(int n) {\n        BigInteger result = BigInteger.valueOf(1);\n        for(int i = 1; i <= n; i++) {\n            result = result.multiply(BigInteger.valueOf(i));\n        }\n        return result;\n    }\n    \n    private boolean isPrime(int n) {\n        int count = 0;\n        for(int i = 1; i <= n; i++) {\n            if(n % i == 0) {\n                count++;\n            }\n            if(count > 2) {\n                return false;\n            }\n        }\n        return true;\n    }\n}\n```
[]