我正在尝试找到数字 x 的最大素数除数。当 x 小于 10 亿时,我的代码可以工作,但是当它大于 10 亿时,它会给出溢出错误,并且调试会突出显示其中包含 Mod 的行。
Sub Largest_Divisor()
Dim x As Double
Dim Q As Integer
Q = 0
Dim L() As Double
x = 999999999#
Dim i As Double
For i = 775145 To 3 Step -2
If x Mod i = 0 Then
If IsPrime(i) Then
ReDim Preserve L(Q) As Double
L(Q) = i
Q = Q + 1
End If
End If
Next i
MsgBox (Application.Max(L))
End Sub