Crates.io | divisors_fixed |
lib.rs | divisors_fixed |
version | 0.4.0 |
source | src |
created_at | 2024-03-29 15:09:14.219674 |
updated_at | 2024-03-31 04:21:27.637265 |
description | A fixed & enhanced version of the divisors crate |
homepage | |
repository | https://github.com/jh05013/divisors |
max_upload_size | |
id | 1190257 |
size | 9,400 |
A minimalistic crate for finding all divisors of an integer. Although its worst-case time complexity is (currently) still O(sqrt(n)), It is practically much faster than the naive method of trying every integers under sqrt(n).
This library works with u8
, u16
, u32
, u64
, u128
,
and usize
types.
This originally started as a clone of the divisors crate with bug fixes (hence the name), but has since evolved with API changes and reimplementations.
let n = 240u32;
println!("{:?}", n.divisors_unordered());
println!("{:?}", n.divisors());
/*
Output:
[1, 2, 4, 8, 16, 3, 6, 12, 24, 48, 5, 10, 20, 40, 80, 15, 30, 60, 120, 240]
[1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 16, 20, 24, 30, 40, 48, 60, 80, 120, 240]
*/
Add this to your Cargo.toml
:
[dependencies]
divisors = "0.4.0"
cargo doc --open
cargo bench
cargo test
MIT.