Functional Programming with Scala
\nobject Solution {\n    lazy val primes: Stream[Int] = 2 #:: Stream.from(3)\n        .filter(x => {\n            primes.takeWhile(_ <= math.sqrt(x)).exists(x%_
```\nobject Solution {\n    lazy val primes: Stream[Int] = 2 #:: Stream.from(3)\n        .filter(x => {\n            primes.takeWhile(_ <= math.sqrt(x)).exists(x%_ == 0) == false\n        })\n\n    val MOD = math.pow(10,9).toInt+7\n    \n    lazy val factorials: Stream[BigInt] = 1 #:: factorials.zip(Stream.from(1))\n        .map(x => x._1 * x._2)\n    \n    def numPrimeArrangements(n: Int): Int = {\n        val primeCount = primes.takeWhile(_ <= n).size\n        \n        ((factorials(n-primeCount) * factorials(primeCount)) % MOD).toInt\n    }\n}\n```
[]