2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
34
Task/Amicable-pairs/PureBasic/amicable-pairs.purebasic
Normal file
34
Task/Amicable-pairs/PureBasic/amicable-pairs.purebasic
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
EnableExplicit
|
||||
|
||||
Procedure.i SumProperDivisors(Number)
|
||||
If Number < 2 : ProcedureReturn 0 : EndIf
|
||||
Protected i, sum = 0
|
||||
For i = 1 To Number / 2
|
||||
If Number % i = 0
|
||||
sum + i
|
||||
EndIf
|
||||
Next
|
||||
ProcedureReturn sum
|
||||
EndProcedure
|
||||
|
||||
Define n, f
|
||||
Define Dim sum(19999)
|
||||
|
||||
If OpenConsole()
|
||||
For n = 1 To 19999
|
||||
sum(n) = SumProperDivisors(n)
|
||||
Next
|
||||
PrintN("The pairs of amicable numbers below 20,000 are : ")
|
||||
PrintN("")
|
||||
For n = 1 To 19998
|
||||
f = sum(n)
|
||||
If f <= n Or f < 1 Or f > 19999 : Continue : EndIf
|
||||
If f = sum(n) And n = sum(f)
|
||||
PrintN(RSet(Str(n),5) + " and " + RSet(Str(sum(n)), 5))
|
||||
EndIf
|
||||
Next
|
||||
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