DefDbl A-Z
Dim fct(20, 1), crlf$, tot, dvsr, num, f
Private Sub Form_Load()
Text1.Text = ""
crlf = Chr(13) + Chr(10)
Form1.Visible = True
For num = 3 To 99999 Step 2
f = factor(num)
tot = 0: dvsr = 1
addOn 1
If tot > num Then
Text1.Text = Text1.Text & num & Str(tot) & crlf
End If
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
Sub addOn(wh)
dvsrSave = dvsr
For i = 0 To fct(wh, 1)
DoEvents
If i > 0 Then dvsr = dvsr * fct(wh, 0)
If wh = f Then
If dvsr <> num Then tot = tot + dvsr
Else
If wh < f Then addOn wh + 1
End If
Next
dvsr = dvsrSave
End Sub
Function factor(num)
diffCt = 0: good = 1
n = Abs(num): If n > 0 Then limit = Sqr(n) Else limit = 0
If limit <> Int(limit) Then limit = Int(limit + 1)
dv = 2: GoSub DivideIt
dv = 3: GoSub DivideIt
dv = 5: GoSub DivideIt
dv = 7
Do Until dv > limit
GoSub DivideIt: dv = dv + 4 '11
GoSub DivideIt: dv = dv + 2 '13
GoSub DivideIt: dv = dv + 4 '17
GoSub DivideIt: dv = dv + 2 '19
GoSub DivideIt: dv = dv + 4 '23
GoSub DivideIt: dv = dv + 6 '29
GoSub DivideIt: dv = dv + 2 '31
GoSub DivideIt: dv = dv + 6 '37
If INKEY$ = Chr$(27) Then s$ = Chr$(27): Exit Function
Loop
If n > 1 Then diffCt = diffCt + 1: fct(diffCt, 0) = n: fct(diffCt, 1) = 1
factor = diffCt
Exit Function
DivideIt:
cnt = 0
Do
q = Int(n / dv)
If q * dv = n And n > 0 Then
n = q: cnt = cnt + 1: If n > 0 Then limit = Sqr(n) Else limit = 0
If limit <> Int(limit) Then limit = Int(limit + 1)
Else
Exit Do
End If
Loop
If cnt > 0 Then
diffCt = diffCt + 1
fct(diffCt, 0) = dv
fct(diffCt, 1) = cnt
End If
Return
End Function