| Crates.io | aliquot |
| lib.rs | aliquot |
| version | 0.1.0 |
| created_at | 2025-08-04 21:06:34.922274+00 |
| updated_at | 2025-08-04 21:06:34.922274+00 |
| description | Generating aliquot sequences |
| homepage | https://github.com/lostinc0de/aliquot |
| repository | https://github.com/lostinc0de/aliquot |
| max_upload_size | |
| id | 1781171 |
| size | 47,040 |
Implementation of a generator of aliquot sequences in Rust
Every aliquot sequence starts with a natural number, for which the sum of its proper divisors is computed. This aliquot sum is the next number in the sequence. Most sequences converge and end with a prime number followed by a one. But this is not always the case and there are some other types of aliquot sequences:
For more information have a look at the Wikipedia page on aliquot sequences.
Using this CLI tool one can compute the aliquot sequences for multiple numbers and output them to stdout. You can pass a list of comma-separated numbers or ranges or a mix of both. I tried to optimize this project as good as I could. The generator uses a cache and can determine, if a number is present in an already computed sequence. The sequence can be completed this way without further computation. Additionally multiple threads may be used to generate the sequences.
Example: Generate the aliquot sequences for the first 100 numbers:
cargo r --release -- 1-100
A more complex example: Generate the aliquot sequences for the first 300 numbers, but leave out 276, since it contains large numbers and results in an overflow error:
cargo r --release -- 1-275,277-300
You can avoid the long computation of such numbers like 276 by defining a maximum value for a number in the resulting sequence. If a number exceeds this value, the sequence is declared as unknown. For example numbers in the sequence should not be greater than four billion:
cargo r --release -- -m 4000000000 1-300
The size of the cache can be set using the CLI switch "-c SIZE". The cache is turned off completely with "-c 0". Otherwise a default value of 1000000 numbers is used, which allocates 8 Mb of memory.
You can generate aliquot sequences in your Rust source using this crate as a lib. Just use cargo add to add the dependency to your project. The generator is implemented generically and the type of the numbers in a sequence can be u16, u32, u64 or u128. To determine an aliquot sequence, you just need a few lines of code:
let mut gener = Generator::<u64>::new();
let aliquot_seq = gener.aliquot_seq(42);
The function aliquot_seq returns an enum of the type AliquotSeq, which differentiates between the following variants:
You can easily print the sequence and its type using the functions sequence_string and type_str from the returned enum:
let n = aliquot_seq.number();
let type_str = aliquot_seq.type_str();
let seq_string = aliquot_seq.seq_string();
println!("{n}: {type_str} {seq_string}");