Advertisement
TizzyT

ProjectEuler_7 -TizzyT

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