How to resolve the algorithm Abundant, deficient and perfect number classifications step by step in the Action! 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 Action! 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 Action! programming language
Source code in the action! programming language
PROC FillSumOfDivisors(CARD ARRAY pds CARD size,maxNum,offset)
CARD i,j
FOR i=0 TO size-1
DO
pds(i)=1
OD
FOR i=2 TO maxNum DO
FOR j=i+i TO maxNum STEP i
DO
IF j>=offset THEN
pds(j-offset)==+i
FI
OD
OD
RETURN
PROC Main()
DEFINE MAXNUM="20000"
DEFINE HALFNUM="10000"
CARD ARRAY pds(HALFNUM+1)
CARD def,perf,abud,i,sum,offset
BYTE CRSINH=$02F0 ;Controls visibility of cursor
CRSINH=1 ;hide cursor
Put(125) PutE() ;clear the screen
PrintE("Please wait...")
def=1 perf=0 abud=0
FillSumOfDivisors(pds,HALFNUM+1,HALFNUM,0)
FOR i=2 TO HALFNUM
DO
sum=pds(i)
IF sum
ELSEIF sum=i THEN perf==+1
ELSE abud==+1 FI
OD
offset=HALFNUM
FillSumOfDivisors(pds,HALFNUM+1,MAXNUM,offset)
FOR i=HALFNUM+1 TO MAXNUM
DO
sum=pds(i-offset)
IF sum
ELSEIF sum=i THEN perf==+1
ELSE abud==+1 FI
OD
PrintF(" Numbers: %I%E",MAXNUM)
PrintF("Deficient: %I%E",def)
PrintF(" Perfect: %I%E",perf)
PrintF(" Abudant: %I%E",abud)
RETURN
You may also check:How to resolve the algorithm Array length step by step in the QB64 programming language
You may also check:How to resolve the algorithm I before E except after C step by step in the TUSCRIPT programming language
You may also check:How to resolve the algorithm Pangram checker step by step in the Fōrmulæ programming language
You may also check:How to resolve the algorithm Function definition step by step in the PostScript programming language
You may also check:How to resolve the algorithm Function composition step by step in the Ruby programming language