作者在 2020-02-23 15:56:32 发布以下内容
Sub Main()
继续:
Dim 测时 As New Diagnostics.Stopwatch
测时.Start()
'===============================================================================================================
Dim 数 = 1000000000000000000
While 数 <= 1000000000000010000
If 判断质数(数) Then ' And 判断质数(数 + 2)
Console.Write("{0} ", 数)
End If
数 += IIf(数 Mod 2 > 0, 2, 1)
End While
'===============================================================================================================
测时.Stop()
Console.WriteLine()
Console.WriteLine("{0}毫秒,按任意键继续,按回车结束。", 测时.Elapsed.TotalMilliseconds)
If Console.ReadKey(True).Key = ConsoleKey.Enter Then
Return
Else
GoTo 继续
End If
End Sub
Function 判断质数(ByVal 数 As Long) As Boolean
Dim 除数 As Integer = 2
Dim 开方 As Double = System.Math.Sqrt(数)
While 开方 >= 除数
If 数 Mod 除数 > 0 Then
除数 = 除数 + IIf(除数 > 2, 2, 1)
Else
Return False
End If
End While
Return True
End Function