fast-factor
A fast integer factorisation library for unsigned integers in Rust.
Usage
Add to your Cargo.toml:
[]
= "0.1.3"
Functions
factor(n)
Returns all factors of n, including 1 and n itself. Returns an empty vector for 0.
assert_eq!;
assert_eq!;
assert_eq!;
proper_factor(n)
Returns all factors of n, excluding n itself.
assert_eq!;
assert_eq!;
exclusive_factor(n)
Returns all factors of n, excluding both 1 and n itself.
assert_eq!;
assert_eq!;
is_prime(n)
Returns true if n is prime. 0 and 1 are not considered prime.
assert!;
assert!;
assert!;
Generics
All functions are generic over any type implementing PrimInt + Unsigned + Roots, so they work with u8, u16, u32, u64, u128, and usize.
factor;
factor;
Algorithm
All functions use trial division up to sqrt(n), then derive complementary factors by division.
| Function | Time complexity |
|---|---|
factor |
O(√n) |
proper_factor |
O(√n) |
exclusive_factor |
O(√n) |
is_prime |
O(√n) |
License
MIT