Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
56
Task/Proper-divisors/PureBasic/proper-divisors.basic
Normal file
56
Task/Proper-divisors/PureBasic/proper-divisors.basic
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
EnableExplicit
|
||||
|
||||
Procedure ListProperDivisors(Number, List Lst())
|
||||
If Number < 2 : ProcedureReturn : EndIf
|
||||
Protected i
|
||||
For i = 1 To Number / 2
|
||||
If Number % i = 0
|
||||
AddElement(Lst())
|
||||
Lst() = i
|
||||
EndIf
|
||||
Next
|
||||
EndProcedure
|
||||
|
||||
Procedure.i CountProperDivisors(Number)
|
||||
If Number < 2 : ProcedureReturn 0 : EndIf
|
||||
Protected i, count = 0
|
||||
For i = 1 To Number / 2
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue