The answer is . I had to cheat somewhat, since Javascript didn't like running a program to find prime factors upto the number necessary. It couldn't even initialise an array that large. Instead I used a large array litteral containing the first 1000 prime numbers.