for i=10 to 1000
    if mod(i/3)<>0 and mod(i/2)<>0 and mod(i/5)<>) and mod(i/7)<>0 then
       debug.print i & "是素数"
    endif
next i
'最后加上3,5,7

解决方案 »

  1.   

    最慢的算法出来了。Private Sub Command1_Click()
        
        Const n As Long = 10000
        
        
        Dim i As Long, j As Long
        
        For i = 2 To n
            For j = 2 To i \ 2
                If i Mod j = 0 Then
                    Exit For
                End If
            Next j
            
            If j = i \ 2 + 1 Then
                Text1 = Text1 & i & ","
            End If
        Next i
    End Sub
      

  2.   

    For i = 10 To 10000
       If ((i Mod 3) <> 0) And ((i Mod 2) <> 0) And ((i Mod 5) <> 0) And ((i Mod 7) <> 0) Then
          Debug.Print i ' & "是素数"
      End IfNext i