Advertisement
TizzyT

ProjectEuler_10 -TizzyT

Jan 19th, 2015
958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.14 KB | None | 0 0
  1. Module PrimeSum 'My solution to Project Euler Problem 10
  2.     Sub Main()
  3.         Dim tbl() As Boolean = PSieve(2000000)
  4.         Dim sum As Double = 0
  5.         For i = 0 To tbl.Length - 1
  6.             If Not tbl(i) Then sum += i
  7.         Next
  8.         Console.WriteLine(sum)
  9.     End Sub
  10.     Function PSieve(ByVal limit As Integer) As Boolean()
  11.         Dim input(limit) As Boolean
  12.         input(0) = True : input(1) = True
  13.         Parallel.For(2, CInt(Math.Sqrt(input.Length)), Sub(i)
  14.                                                            If Not input(i) Then
  15.                                                                Dim j As Integer = 2 * i
  16.                                                                While j <= input.Length - 1
  17.                                                                    input(j) = True
  18.                                                                    j += i
  19.                                                                End While
  20.                                                            End If
  21.                                                        End Sub)
  22.         Return input
  23.     End Function
  24. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement