找出所有二位绝对素数 vb程序

来源:百度知道 编辑:UC知道 时间:2024/05/30 08:09:16
一个自然数是素数,且它的数字位置经过任意对换后仍为素数,则称为绝对素数。

Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Dim SH As Integer
For i = 11 To 99 Step 2
SH = SuShu(i)
If SH = 1 Then
SH = 0
j = Val(Right(i, 1) & Left(i, 1))
SH = SuShu(j)
If SH = 1 Then
Print i
End If
End If
Next
End Sub

Private Function SuShu(i As Integer) As Integer
If i = 2 Or i = 3 Then
SuShu = 1
Exit Function
End If
If i Mod 2 = 0 Then
SuShu = 0
Exit Function
End If
Dim m As Integer
Dim j As Integer
m = Int(Sqr(i))
For j = 3 To m Step 2
If i Mod j = 0 Then
SuShu = 0
Exit Function
End If
Next
SuShu = 1
End Function

'以下手写,不知道有没有字打错,如有打错,请见谅
sub trytry
dim i as integer
for i = 10 to 99
if isSS(i) then print i
next
end sub

function isSS (byval n as integer ) as boolean