求[100,800]范围内的素数的个数

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/30 02:26:33
求[100,800]范围内的素数的个数
xJ@_lp1-h/PP)p!"vL$3!ʭtJ ȶ>'N[&g|s Z 0qt7/tdfEQ̥A}VpA_fGRzp\6ڿ `9Ԡ›У^ U ШN h%g'rƺӝ*ZwI 1V±AYeP)P?1dmTͫGnM+,rE)ɞ lXpbUȹݧ

求[100,800]范围内的素数的个数
求[100,800]范围内的素数的个数

求[100,800]范围内的素数的个数
Function Prime(a As Integer) As Boolean
Dim k As Integer, isprime As Boolean
If a < 2 Then
isprime = False
Else
isprime = True
k = 2
Do While k < a
If a Mod k = 0 Then
isprime = False
Exit Do
Else
k = k + 1
End If
Loop
End If
Prime = isprime
End Function
Private Sub Command1_Click()
Dim i As Integer, geshu As Integer
For i = 100 To 800
If Prime(i) Then
geshu = geshu + 1
End If
Next i
Debug.Print geshu '114个
End Sub