Find the sum of all the positive square-free integers whose divisors add up to 288.
The numbers, followed by their divisors:
138
1 23 3 69 2 46 6 138
154
1 11 7 77 2 22 14 154
165
1 11 5 55 3 33 15 165
213
1 71 3 213
235
1 47 5 235
253
1 23 11 253
The total of 138+154+165+213+235+253 = 1158
DefDbl A-Z
Dim crlf$, fct(20, 1), sdiv, f, dvsr, ndiv, divlist(100)
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For n = 2 To 288
sdiv = 0: dvsr = 1
ndiv = 0
f = factor(n)
good = 1
For i = 1 To f
If fct(i, 1) > 1 Then good = 0: Exit For
Next
If good Then
addthem 1
If sdiv = 288 Then
Text1.Text = Text1.Text & n & crlf
For i = 1 To ndiv
Text1.Text = Text1.Text & Str(divlist(i))
Next
Text1.Text = Text1.Text & crlf & crlf
tot = tot + n
End If
End If
DoEvents
Next
Text1.Text = Text1.Text & crlf & tot & " done"
End Sub
Sub addthem(wh)
For howmany = 0 To fct(wh, 1)
savedvsr = dvsr
dvsr = Int(dvsr * fct(wh, 0) ^ howmany + 0.5)
If wh = f Then
sdiv = sdiv + dvsr
ndiv = ndiv + 1
divlist(ndiv) = dvsr
Else
addthem wh + 1
End If
dvsr = savedvsr
Next
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
|
Posted by Charlie
on 2019-10-18 13:34:48 |