RosettaCodeData/Task/Abundant-odd-numbers/PureBasic/abundant-odd-numbers.basic
2023-07-01 13:44:08 -04:00

70 lines
1.3 KiB
Text

NewList l_sum.i()
Procedure.i sum_proper_divisors(n.i)
Define.i sum, i=3, j
Shared l_sum()
AddElement(l_sum())
l_sum()=1
While i<Sqr(n)+1
If n%i=0
sum+i
AddElement(l_sum())
l_sum()=i
j=n/i
If i<>j
sum+j
AddElement(l_sum())
l_sum()=j
EndIf
EndIf
i+2
Wend
ProcedureReturn sum+1
EndProcedure
If OpenConsole("Abundant_odd_numbers")
Define.i n, c, s
n=1
c=0
While c<25
ClearList(l_sum())
s=sum_proper_divisors(n)
If n<s
SortList(l_sum(),#PB_Sort_Ascending)
c+1
Print(RSet(Str(c),3)+": "+RSet(Str(n),6)+" -> "+RSet(Str(s),6))
ForEach l_sum()
If ListIndex(l_sum())=0
Print(" = ")
Else
Print("+")
EndIf
Print(Str(l_sum()))
Next
PrintN("")
EndIf
n+2
Wend
n-2
While c<1000
s=sum_proper_divisors(n+2)
c+Bool(n<s)
n+2
Wend
PrintN(~"\nThe one thousandth abundant odd number is: "+Str(n)+
~"\n\tand the proper divisor sum is: "+Str(s))
n=1000000001-2
Repeat
n+2
s=sum_proper_divisors(n)
Until n<s
PrintN("The first abundant odd number above one billion is: "+Str(n)+
~"\n\tand the proper divisor sum is: "+Str(s))
Input()
EndIf