I found an answer on Stack Overflow a few days ago. I adapted it a bit to make it more parallel and easier to read. I might have made a mistake. I tested it in my computer: Core i7 Second Gen (3GHz) with 12GB of RAM. It took a few seconds to solve most of the numbers less than 50,000,000. However, it took around 6:32 seconds to solve 100,000,000. It took around 47 mins to solve 500,000,000. It crashed 11 hours after solving 1.5 billion. private static void GetPrimeNumbers(int max) { var allPossibleNumbers = Enumerable.Range(3, max-3); var possiblePrime = allPossibleNumbers .AsParallel() .Where(n => Enumerable.Range(2, (int)Math.Sqrt(n)) .All(i => n % i != 0) ) ; possiblePrime .ToArray() .AsParallel() .Dump() ; }