How to resolve the algorithm Abundant, deficient and perfect number classifications step by step in the Bracmat programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Abundant, deficient and perfect number classifications step by step in the Bracmat programming language
Table of Contents
Problem Statement
These define three classifications of positive integers based on their proper divisors. Let P(n) be the sum of the proper divisors of n where the proper divisors are all positive divisors of n other than n itself.
6 has proper divisors of 1, 2, and 3. 1 + 2 + 3 = 6, so 6 is classed as a perfect number.
Calculate how many of the integers 1 to 20,000 (inclusive) are in each of the three classes. Show the results here.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Abundant, deficient and perfect number classifications step by step in the Bracmat programming language
Source code in the bracmat programming language
( clk$:?t0
& ( multiples
= prime multiplicity
. !arg:(?prime.?multiplicity)
& !multiplicity:0
& 1
| !prime^!multiplicity*(.!multiplicity)
+ multiples$(!prime.-1+!multiplicity)
)
& ( P
= primeFactors prime exp poly S
. !arg^1/67:?primeFactors
& ( !primeFactors:?^1/67&0
| 1:?poly
& whl
' ( !primeFactors:%?prime^?exp*?primeFactors
& !poly*multiples$(!prime.67*!exp):?poly
)
& -1+!poly+1:?poly
& 1:?S
& ( !poly
: ?
+ (#%@?s*?&!S+!s:?S&~)
+ ?
| 1/2*!S
)
)
)
& 0:?deficient:?perfect:?abundant
& 0:?n
& whl
' ( 1+!n:~>20000:?n
& P$!n
: (
| !n&1+!perfect:?perfect
| >!n&1+!abundant:?abundant
)
)
& out$(deficient !deficient perfect !perfect abundant !abundant)
& clk$:?t1
& out$(flt$(!t1+-1*!t0,2) sec)
& clk$:?t2
& ( P
= f h S
. 0:?f
& 0:?S
& whl
' ( 1+!f:?f
& !f^2:~>!n
& ( !arg*!f^-1:~/:?g
& !S+!f:?S
& ( !g:~!f&!S+!g:?S
|
)
|
)
)
& 1/2*!S
)
& 0:?deficient:?perfect:?abundant
& 0:?n
& whl
' ( 1+!n:~>20000:?n
& P$!n
: (
| !n&1+!perfect:?perfect
| >!n&1+!abundant:?abundant
)
)
& out$(deficient !deficient perfect !perfect abundant !abundant)
& clk$:?t3
& out$(flt$(!t3+-1*!t2,2) sec)
);
You may also check:How to resolve the algorithm Towers of Hanoi step by step in the Gambas programming language
You may also check:How to resolve the algorithm Sort stability step by step in the Nim programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the M4 programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the Tcl programming language
You may also check:How to resolve the algorithm Latin Squares in reduced form step by step in the F# programming language