Learn R Programming

FunWithNumbers (version 1.1)

aliquot: Generate the Aliquot sequence.

Description

Each term in the aliquot sequence is generated by summing all proper divisors of the previous term. The value "1" is included in this collection of divisors. In number theory, aliquot is closely related to terms such as "sociable" and "amicable" numbers

Usage

aliquot(x, maxiter = 100)

Value

A vector of bigz integers ...

Arguments

x

An integer or a bigz integer to start the desired sequence

maxiter

Set a limit on the number of terms to calculate. See Details for reasons why to do so.

Author

Carl Witthoft, carl@witthoft.com

Details

While many aliquot sequences terminate in the values c(prime_number, 1, 0), many numbers drop into a short loop or a repeating value (perfect numbers do this). If the sequence repeats or terminates, the sequence is returned. If either maxiter is reached or the sequence drops into a loop (and thus maxiter will be triggered), a warning notice is generated and the sequence so far is returned.

Examples

Run this code
aliquot(20)
# 20 22 14 10 8  7  1
aliquot (95)
# repeats '6' forever
# 95 25 6  6

Run the code above in your browser using DataLab