How to resolve the algorithm Abundant odd numbers step by step in the PureBasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Abundant odd numbers step by step in the PureBasic programming language
Table of Contents
Problem Statement
An Abundant number is a number n for which the sum of divisors σ(n) > 2n, or, equivalently, the sum of proper divisors (or aliquot sum) s(n) > n.
12 is abundant, it has the proper divisors 1,2,3,4 & 6 which sum to 16 ( > 12 or n); or alternately, has the sigma sum of 1,2,3,4,6 & 12 which sum to 28 ( > 24 or 2n).
Abundant numbers are common, though even abundant numbers seem to be much more common than odd abundant numbers. To make things more interesting, this task is specifically about finding odd abundant numbers.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Abundant odd numbers step by step in the PureBasic programming language
Source code in the purebasic programming language
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
You may also check:How to resolve the algorithm Create a file step by step in the Objective-C programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the Java Long type version programming language
You may also check:How to resolve the algorithm Remove duplicate elements step by step in the Prolog programming language
You may also check:How to resolve the algorithm Generate Chess960 starting position step by step in the Go programming language
You may also check:How to resolve the algorithm Range expansion step by step in the SNOBOL4 programming language