Code:'This code was written by Mert Ener Private Declare Function GetTime Lib "winmm.dll" Alias "timeGetTime" () As Long Private mStartTime As Object Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click mStartTime = GetTime Dim l, n As Long : Dim m As Long = 1 : Dim p As New List(Of Long)(New Long() {2}) For n = 0 To (Me.TextBox1.Text) - 2 'The textbox you entered for the nth prime. m = m + 2 For l = 1 To n If m Mod p(l) = 0 Then m += 2 l = 0 End If Next p.Add(m) Next Me.TextBox2.Text = p(n) 'The textbox you get the result. MsgBox("It took me " & GetTime - mStartTime & " milliseconds to find your prime number.") End Sub




Reply With Quote