如果a的所有正因子和等于b,b的所有正因子和等于a,因子包括1但不包括本身,且a不等于b,则称a,b为亲密数对。一般通过叠代编程求出相应的亲密数对。
设 a=3*2^(x-1)-1, b=3*2^x-1,c=9*2^(2x-1)-1,这里x是大于1的自然数,如果a、b、c全是素数的话。那么2*x*ab与2*x*c。便是一对相亲和数。
Public Function IsSushu(ByVal pa As Integer) As Boolean
Dim pb As Integer = pa - 1
Dim res As Boolean = True
For i = 2 To pb
If pa Mod i = 0 Then
res = False
Exit For
End If
Next i
Return res
End Function
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim st As String = ""
Dim a As Integer, b As Integer, c As Integer
For i = 2 To 10
a = 3 * 2 ^ (i - 1) - 1
b = 3 * 2 ^ i - 1
c = 9 * 2 ^ (2 * i - 1) - 1
If IsSushu(a) And IsSushu(b) And IsSushu(c) Then
st = st & "相亲数" & 2 * i * a * b & " " & 2 * i * c & vbCrLf
End If
Next
TextBox6.Text = st
End Sub