print "2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97"
搞定收工~~~
2010-03-26 10:14:24 補充:
'宣告變數
Dim I As Integer
Dim Tmp As Integer
Dim XT(100) As Boolean
2010-03-26 10:14:29 補充:
'將所有值設定成true
For I = 0 To 100
XT(I) = True
Next I
'從2開始到100
For I = 2 To 100
'如果是質數
If XT(I) = True Then
'存到text1
Text1.Text = Text1.Text & I & ","
'將後面的倍數都設為false,直到小於100
Tmp = 2
Do Until Tmp * I > 100
XT(Tmp * I) = False
Tmp = Tmp + 1
Loop
End If
參考: 危機百顆查到的, 最慢但是最簡單的原理, 最慢但是最簡單的原理
Option Explicit
Private Sub Form_Load()
Const n As Integer = 100
Dim flag As Integer
Dim i As Integer, j As Integer
Dim S As String
S = "2"
For i = 3 To n Step 2
flag = 0
For j = 3 To i - 1 Step 2
If i Mod j = 0 Then flag = flag + 1
Next
If flag = 0 Then S = S & " " & i
Next
Text1.SelText = S
End Sub
2010-04-02 20:48:32 補充:
003的方法看起來沒問題
剛剛想來做個測速實驗
卻發現會有範圍才到2000...
答案裡會有2000 1998 1996 1994 ...等等非質數者
2010-04-02 20:50:34 補充:
2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,
2010-04-02 20:50:37 補充:
155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,
範圍200的答案