Proper divisors: Difference between revisions

no edit summary
No edit summary
Line 3,923:
max: 15120 => (...79...)
</pre>
 
=={{header|VBA}}==
<lang vb>Public Sub Proper_Divisor()
Dim t() As Long, i As Long, l As Long, j As Long, c As Long
For i = 1 To 10
Debug.Print "Proper divisor of " & i & " : " & Join(S(i), ", ")
Next
For i = 2 To 20000
l = UBound(S(i)) + 1
If l > c Then c = l: j = i
Next
Debug.Print "Number in the range 1 to 20,000 with the most proper divisors is : " & j
Debug.Print j & " count " & c & " proper divisors"
End Sub
 
Private Function S(n As Long) As String()
'returns the proper divisors of n
Dim i As Long, j As Long, t() As String, c As Long
't = list of proper divisor of n
If n > 1 Then
For j = 1 To n \ 2
If n Mod j = 0 Then
ReDim Preserve t(c)
t(c) = j
c = c + 1
End If
Next
End If
S = t
End Function</lang>
{{out}}
<pre>Proper divisor of 1 :
Proper divisor of 2 : 1
Proper divisor of 3 : 1
Proper divisor of 4 : 1, 2
Proper divisor of 5 : 1
Proper divisor of 6 : 1, 2, 3
Proper divisor of 7 : 1
Proper divisor of 8 : 1, 2, 4
Proper divisor of 9 : 1, 3
Proper divisor of 10 : 1, 2, 5
Number in the range 1 to 20,000 with the most proper divisors is : 15120
15120 count 79 proper divisors</pre>
 
=={{header|zkl}}==
Anonymous user