Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module PrimeAtIndex 'My solution to Project Euler Problem 7
- Sub Main()
- Dim tble() As Boolean = PSieve(10001 ^ 2)
- Dim cnt As Integer = 0
- For i = 0 To tble.Length - 1
- If Not tble(i) Then
- cnt += 1
- If cnt = 10001 Then
- Console.WriteLine(i)
- Exit For
- End If
- End If
- Next
- Console.ReadKey()
- End Sub
- Function PSieve(ByVal limit As Integer) As Boolean()
- Dim input(limit) As Boolean
- input(0) = True : input(1) = True
- Parallel.For(2, CInt(Math.Sqrt(input.Length)), Sub(i)
- If Not input(i) Then
- Dim j As Integer = 2 * i
- While j <= input.Length - 1
- input(j) = True
- j += i
- End While
- End If
- End Sub)
- Return input
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement