iI found an answer inon Stack Overflow a few days ago, i. I adapted it a bit to make it more parallel and easier to read.
--> i I might have made a mistake, mind me if i did. I I tested it in my computer. Core: Core i7 Second Gen (3Ghz3GHz). 12Gb with 12GB of ramRAM.
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. took It took around 47 mins to solve 500,000,000. and It crashed 11 hours after solving 1.5 billionsbillion.
MY CODE:
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()
;
}