Aliquot sequence classifications: Difference between revisions
Used "int64" instead of "int" for aliquots. Some other minor changes.
m (BASIC256 moved to the BASIC section.) |
(Used "int64" instead of "int" for aliquots. Some other minor changes.) |
||
Line 3,678:
=={{header|Nim}}==
<syntaxhighlight lang="nim">import std/[math, strformat, times]
from std/strutils import
type
# Classification categories.
Category {.pure.} = enum
Unknown
Terminating = "terminating"
Line 3,698 ⟶ 3,695:
# Aliquot sequence.
AliquotSeq = seq[
const Limit = 2^47 # Limit beyond which the category is considered to be "NonTerminating".
Line 3,704 ⟶ 3,701:
#---------------------------------------------------------------------------------------------------
proc sumProperDivisors(n:
## Compute the sum of proper divisors.*
if n == 1: return 0
result = 1
for d in 2..sqrt(n.
if n mod d == 0:
inc result, d
if n div d != d:
#---------------------------------------------------------------------------------------------------
iterator aliquotSeq(n:
## Yield the elements of the aliquot sequence of "n".
## Stopped if the current value is null or equal to "n".
Line 3,737 ⟶ 3,734:
#---------------------------------------------------------------------------------------------------
proc classification(n:
## Return the category of the aliquot sequence of a number "n" and the sequence itself.
Line 3,769 ⟶ 3,766:
for n in 1..10:
let (cat, aseq) = classification(n)
echo fmt"{n:14}: {cat:<20} {aseq}"
echo ""
for n in [int64 11, 12, 28, 496, 220, 1184, 12496, 1264460,
790, 909, 562, 1064, 1488, 15355717786080
let (cat, aseq) = classification(n)
echo fmt"{n:14}: {cat:<20} {aseq}"
|