|
| bool | tgen::math::is_prime (uint64_t n) |
| | Checks if a number is prime.
|
| std::vector< uint64_t > | tgen::math::factor (uint64_t n) |
| | Factors a number into primes.
|
| std::vector< std::pair< uint64_t, int > > | tgen::math::factor_by_prime (uint64_t n) |
| | Factors a number into primes and its powers.
|
| uint64_t | tgen::math::modular_inverse (uint64_t a, uint64_t mod) |
| | Computes modular inverse.
|
| uint64_t | tgen::math::totient (uint64_t n) |
| | Euler's totient function.
|
| const std::pair< std::vector< uint64_t >, std::vector< uint64_t > > & | tgen::math::prime_gaps () |
| | Fetches prime gaps.
|
| std::pair< uint64_t, uint64_t > | tgen::math::prime_gap_upto (uint64_t right) |
| | Largest prime gap up to given number.
|
| const std::vector< uint64_t > & | tgen::math::highly_composites () |
| | Fetches highly composite numbers.
|
| uint64_t | tgen::math::highly_composite_upto (uint64_t right) |
| | Largest highly composite number up to given number.
|
| uint64_t | tgen::math::gen_prime (uint64_t left, uint64_t right) |
| | Generates a random prime in given range.
|
| uint64_t | tgen::math::prime_from (uint64_t left) |
| | Computes smallest prime from given value.
|
| uint64_t | tgen::math::prime_upto (uint64_t right) |
| | Computes largest prime up to given value.
|
| int | tgen::math::num_divisors (uint64_t n) |
| | Computes the number of divisors of a given number.
|
| uint64_t | tgen::math::gen_divisor_count (uint64_t left, uint64_t right, int divisor_count) |
| | Generates random number in range with a given prime number of divisors.
|
| uint64_t | tgen::math::gen_congruent (uint64_t left, uint64_t right, std::vector< uint64_t > rems, std::vector< uint64_t > mods) |
| | Generates random number in range given modular congruences.
|
| uint64_t | tgen::math::gen_congruent (uint64_t left, uint64_t right, uint64_t rem, uint64_t mod) |
| | Generates random number in range given a modular congruence.
|
| uint64_t | tgen::math::congruent_from (uint64_t left, std::vector< uint64_t > rems, std::vector< uint64_t > mods) |
| | Computes smallest congruent from given value.
|
| uint64_t | tgen::math::congruent_from (uint64_t left, uint64_t rem, uint64_t mod) |
| | Computes smallest congruent from given value.
|
| uint64_t | tgen::math::congruent_upto (uint64_t right, std::vector< uint64_t > rems, std::vector< uint64_t > mods) |
| | Computes largest congruent up to given value.
|
| uint64_t | tgen::math::congruent_upto (uint64_t right, uint64_t rem, uint64_t mod) |
| | Computes largest congruent up to given value.
|
| const std::vector< uint64_t > & | tgen::math::fibonacci () |
| | Fetches Fibonacci numbers.
|
| std::vector< int > | tgen::math::gen_partition (int n, int part_left=1, std::optional< int > part_right=std::nullopt) |
| | Generates a random partition of a number.
|
| std::vector< int > | tgen::math::gen_partition_fixed_size (int n, int k, int part_left=0, std::optional< int > part_right=std::nullopt) |
| | Generates a random partition with fixed size of a number.
|
| std::vector< uint64_t > | tgen::math::gen_partition_fixed_size_fast (uint64_t n, int k, uint64_t part_left=0, std::optional< uint64_t > part_right=std::nullopt) |
| | Generates a fast non-uniform partition with fixed size.
|
| template<typename T> |
| std::vector< std::vector< T > > | tgen::math::partition_elements (std::vector< T > elements, int k, int min_size=0, std::optional< uint64_t > max_size=std::nullopt) |
| | Partitions a vector into k ordered groups.
|
Operations regarding number theory and related topics.
Prints primes from 100 to 200.
Prints random two-digit number that is even and congruent to 1 mod 3.
| std::vector< uint64_t > tgen::math::gen_partition_fixed_size_fast |
( |
uint64_t | n, |
|
|
int | k, |
|
|
uint64_t | part_left = 0, |
|
|
std::optional< uint64_t > | part_right = std::nullopt ) |
|
inline |
Generates a fast non-uniform partition with fixed size.
- Parameters
-
| n | Number to partition. |
| k | Number of parts. |
| part_left | Minimum part value. |
| part_right | Maximum part value. |
- Precondition
- n >= k > 0.
part_left >= 0.
Partition is ordered (so technically a composition). That is, (1, 1, 2) != (1, 2, 1). If part_right is not set, part_right is considered to be n (unbounded).
Inspired by jngen: draw k - 1 random delimiters with replacement, sort them, and recover part sizes from the gaps.
- Returns
- A random ordered partition of n with length k and values in [part_left, part_right].
- Exceptions
-
| std::runtime_error | if there is no such partition. |
- Note
- This operation is not uniformly random.
Complexity
O(k log k).
Examples
std::vector< uint64_t > gen_partition_fixed_size_fast(uint64_t n, int k, uint64_t part_left=0, std::optional< uint64_t > part_right=std::nullopt)
Generates a fast non-uniform partition with fixed size.
Definition at line 3259 of file tgen.h.