Proper divisors: Difference between revisions

m (added a ;Related task: (bold) header.)
Line 2,076:
Result = num(15120)-divisor_count(79).
</lang>
 
=={{header|PureBasic}}==
<lang PureBasic>
EnableExplicit
 
Procedure ListProperDivisors(Number, List Lst())
If Number < 2 : ProcedureReturn : EndIf
Protected i
For i = 1 To Number - 1
If Number % i = 0
AddElement(Lst())
Lst() = i
EndIf
Next
EndProcedure
 
Procedure CountProperDivisors(Number)
If Number < 2 : ProcedureReturn 0 : EndIf
Protected i, count = 0
For i = 1 To Number - 1
If Number % i = 0
count + 1
EndIf
Next
ProcedureReturn count
EndProcedure
Define n, count, most = 1, maxCount = 0
If OpenConsole()
PrintN("The proper divisors of the following numbers are : ")
PrintN("")
NewList lst()
For n = 1 To 10
ListProperDivisors(n, lst())
Print(RSet(Str(n), 3) + " -> ")
If ListSize(lst()) = 0
Print("(None)")
Else
ForEach lst()
Print(Str(lst()) + " ")
Next
EndIf
ClearList(lst())
PrintN("")
Next
For n = 2 To 20000
count = CountProperDivisors(n)
If count > maxCount
maxCount = count
most = n
EndIf
Next
PrintN("")
PrintN(Str(most) + " has the most proper divisors, namely " + Str(maxCount))
PrintN("")
PrintN("Press any key to close the console")
Repeat: Delay(10) : Until Inkey() <> ""
CloseConsole()
EndIf
</lang>
 
{{out}}
<pre>
The proper divisors of the following numbers are :
 
1 -> (None)
2 -> 1
3 -> 1
4 -> 1 2
5 -> 1
6 -> 1 2 3
7 -> 1
8 -> 1 2 4
9 -> 1 3
10 -> 1 2 5
 
15120 has the most proper divisors, namely 79
</pre>
 
=={{header|Python}}==
9,486

edits