How to resolve the algorithm Abundant, deficient and perfect number classifications step by step in the AppleScript 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 AppleScript 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 AppleScript programming language
Source code in the applescript programming language
on aliquotSum(n)
if (n < 2) then return 0
set sum to 1
set sqrt to n ^ 0.5
set limit to sqrt div 1
if (limit = sqrt) then
set sum to sum + limit
set limit to limit - 1
end if
repeat with i from 2 to limit
if (n mod i is 0) then set sum to sum + i + n div i
end repeat
return sum
end aliquotSum
on task()
set {deficient, perfect, abundant} to {0, 0, 0}
repeat with n from 1 to 20000
set s to aliquotSum(n)
if (s < n) then
set deficient to deficient + 1
else if (s > n) then
set abundant to abundant + 1
else
set perfect to perfect + 1
end if
end repeat
return {deficient:deficient, perfect:perfect, abundant:abundant}
end task
task()
{deficient:15043, perfect:4, abundant:4953}
You may also check:How to resolve the algorithm Strip whitespace from a string/Top and tail step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Reduced row echelon form step by step in the Visual FoxPro programming language
You may also check:How to resolve the algorithm Church numerals step by step in the Phix programming language
You may also check:How to resolve the algorithm Polynomial long division step by step in the zkl programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Verbexx programming language