 All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars  perplexus dot info  SUM = PR0DUCT (Posted on 2017-10-18) List all the integers N, below 10000, such that the sum of their proper divisors (i.e. N excluded) equals their product.

Counterexample:
take 12: s(1,2,3,4,6)=16; p(1,2,3,4,6)=144;
so 12 is not on the list.

 See The Solution Submitted by Ady TZIDON No Rating Comments: ( Back to comment list | You must be logged in to post comments.) computer solution | Comment 1 of 3
DefDbl A-Z
Dim fct(20, 1), crlf\$, fsum, fprod, propDiv, f, n
Function mform\$(x, t\$)
a\$ = Format\$(x, t\$)
If Len(a\$) < Len(t\$) Then a\$ = Space\$(Len(t\$) - Len(a\$)) & a\$
mform\$ = a\$
End Function

Text1.Text = ""
crlf\$ = Chr(13) + Chr(10)

Form1.Visible = True

For n = 2 To 10000
f = factor(n)
fsum = 0: fprod = 1
propDiv = 1
doPropDiv 1
DoEvents

If fsum = fprod And fsum <> 1 Then
Text1.Text = Text1.Text & Str(n) & Str(fsum) & crlf\$
DoEvents
End If
Next n
End Sub

Sub doPropDiv(wh)
For i = 0 To fct(wh, 1)
pdSave = propDiv
propDiv = Int(propDiv * fct(wh, 0) ^ i + 0.5)
If wh < f Then
doPropDiv wh + 1
Else
If propDiv < n Then
fsum = fsum + propDiv
fprod = fprod * propDiv
End If
End If
propDiv = pdSave
Next
End Sub

Function factor(num)
diffCt = 0: good = 1
nm1 = Abs(num): If nm1 > 0 Then limit = Sqr(nm1) 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 nm1 > 1 Then diffCt = diffCt + 1: fct(diffCt, 0) = nm1: fct(diffCt, 1) = 1
factor = diffCt
Exit Function

DivideIt:
cnt = 0
Do
q = Int(nm1 / dv)
If q * dv = nm1 And nm1 > 0 Then
nm1 = q: cnt = cnt + 1: If nm1 > 0 Then limit = Sqr(nm1) 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

finds only 6 due to the additional requirement that the sum (and therefore product) fsum <> 1. Before that requirement was imposed, every prime number was also included, as it should be for the actual wording of the puzzle.

 Posted by Charlie on 2017-10-18 10:52:00 Please log in:

 Search: Search body:
Forums (4)