Since speed will be an issue here, it's more efficient to square-root x, round it up, and store that value to check primes[n] against.

There's some interesting posts here on prime numbers, isPrime...