Private Sub Command1_Click()
Dim temp1 As Long, temp2 As Long, i As Long
For i = 1 To 20000
getxiangqinshu i, temp1
If Not temp1 = i Then
getxiangqinshu temp1, temp2
If i = temp2 Then Debug.Print i; temp1
End If
Next
MsgBox "ok"
End Sub
Function getxiangqinshu(ByVal x As Long, ByRef y As Long) As Boolean
Dim i As Long, max As Long
max = IIf(x Mod 2 = 0, x \ 2, IIf(x Mod 3 = 0, x \ 3, x \ 5))
y = 0
For i = 1 To max
If x Mod i = 0 Then y = y + i
Next
End Function
返回:
220 284
284 220
1184 1210
1210 1184
2620 2924
2924 2620
5020 5564
5564 5020
6232 6368
6368 6232
10744 10856
10856 10744
12285 14595
14595 12285
17296 18416
18416 17296
Private Sub Command1_Click()
Dim temp1 As Long, temp2 As Long, i As Long
For i = 1 To 10000
getxiangqinshu i, temp1
getxiangqinshu temp1, temp2
If i = temp2 And Not i = temp1 Then Debug.Print i; temp1
Next
End Sub
Function getxiangqinshu(ByVal x As Long, ByRef y As Long) As Boolean
Dim i As Long, max As Long
max = x \ 2
y = 0
For i = 1 To max
If x Mod i = 0 Then y = y + i
Next
End Function
Private Sub Command1_Click()
Dim temp1 As Long, temp2 As Long, i As Long
For i = 1 To 100000
getxiangqinshu i, temp1
If Not temp1 = i Then
getxiangqinshu temp1, temp2
If i = temp2 Then Debug.Print i; temp1
End If
Next
MsgBox "ok"
End Sub
Function getxiangqinshu(ByVal x As Long, ByRef y As Long) As Boolean
Dim i As Long, max As Long
max = Int(Sqr(x))
y = 1
For i = 2 To max - 1
If x Mod i = 0 Then y = y + i + x \ i
Next
If x Mod max = 0 Then y = y + max
End Function