推 Changsunche:感謝,測試之後若有問題還會在肚上來發問的^W^ 10/01 18:02
'找出範圍內所有整數質數
'VB .NET
Dim nonprimes(0) As Boolean
Sub getAllPrime(ByVal top As Integer)
ReDim nonprimes(top)
Dim value As New MyInt(Of Integer)
nonprimes(0) = True
nonprimes(1) = True
Dim i As Integer = 2
'用篩法標記prime和nonprime
While i <= top / i
'這邊用myInt class,速度會比用isPrime() function慢
value.setting(i)
If value.isPrime() Then
For j As Integer = 2 To top / i
If j * i <= top Then
nonprimes(j * i) = True
End If
Next
End If
i += 1
End While
End Sub
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 120.124.134.62