The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

This problem is very simple as I can reuse the parasitic prime generation from my solution to Problem 7 which also requires Prototype.ps.

123456789101112131415161718192021222324

functionNew-PrimeFinder{$prototype=New-PrimeGenerator$prototype|Add-FunctionFindPrimesLessThan{param($value)if($this.Bound-lt$value){$finder.BoundIncrement=$value-$this.Bound$this.Expand()}return$this.Primes|?{$_-lt$value}}$prototype}functionSolve-Problem10{param($value=2000000)$finder=New-PrimeFinder$finder.FindPrimesLessThan($value)|%{[long]$sum=0}{$sum+=$_}{$sum}}Write-Host"Elapsed Time (s): "(Measure-Command{Solve-Problem10}).TotalSecondsWrite-Host"Solution: "(Solve-Problem10)ElapsedTime(s):1999.6739304Solution:142913828922