Re: [VB6 ] 找出範圍內的質數,想請各位幫忙縮短...

看板Visual_Basic作者 (沒$結婚幹嘛,有$幹嘛結婚)時間16年前 (2009/10/01 14:06), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/4 (看更多)
'找出範圍內所有整數質數 '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

10/01 18:02, , 1F
感謝,測試之後若有問題還會在肚上來發問的^W^
10/01 18:02, 1F
文章代碼(AID): #1An4RJcF (Visual_Basic)
討論串 (同標題文章)
文章代碼(AID): #1An4RJcF (Visual_Basic)