pub fn with_primes(primes: &[u64], n: usize) -> Vec<u64>Expand description
Generates the first n smooth numbers whose prime factors are among primes.
§Examples
If primes is empty, the numbers cannot have any prime factor,
hence the only smooth number in this case is 1.
assert_eq!(with_primes(&[], 0), []);
assert_eq!(with_primes(&[], 1), [1]);
assert_eq!(with_primes(&[], 10), [1]);If primes contains a single element, the numbers can only have the prime factor primes[0],
hence we obtain the sequence of the powers of primes[0].
assert_eq!(with_primes(&[2], 10), [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]);If primes == &[2, 3], the numbers can only have the prime factors 2 and 3,
hence we obtain the sequence of the numbers of the form 2^i * 3^j,
also known as Pratt’s sequence.
See the pratt function for a specialized algorithm to generate this sequence.
assert_eq!(with_primes(&[2, 3], 10), [1, 2, 3, 4, 6, 8, 9, 12, 16, 18]);