|
| 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 r) |
| | 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 r) |
| | Largest highly composite number up to given number.
|
| uint64_t | tgen::math::gen_prime (uint64_t l, uint64_t r) |
| | Generates a random prime in given range.
|
| uint64_t | tgen::math::prime_from (uint64_t l) |
| | Computes smallest prime from given value.
|
| uint64_t | tgen::math::prime_upto (uint64_t r) |
| | 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 l, uint64_t r, int divisor_count) |
| | Generates random number in range with a given prime number of divisors.
|
| uint64_t | tgen::math::gen_congruent (uint64_t l, uint64_t r, 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 l, uint64_t r, uint64_t rem, uint64_t mod) |
| | Generates random number in range given a modular congruence.
|
| uint64_t | tgen::math::gen_even (uint64_t l, uint64_t r) |
| | Generates random even number in a given range.
|
| uint64_t | tgen::math::gen_odd (uint64_t l, uint64_t r) |
| | Generates random odd number in a given range.
|
| const std::vector< uint64_t > & | tgen::math::fibonacci () |
| | Fetches Fibonacci numbers.
|
| std::vector< int > | tgen::math::gen_partition (int n, int part_l=1, int part_r=-1) |
| | Generates a random partition of a number.
|
| std::vector< int > | tgen::math::gen_partition_fixed_size (int n, int k, int part_l=0, int part_r=-1) |
| | Generates a random partition with fixed size of a number.
|
Operations regarding number theory and related topics.
std::cout << p << std::endl;
}
std::pair< uint64_t, uint64_t > prime_gap_upto(uint64_t r)
Largest prime gap up to given number.
std::vector< int > gen_partition_fixed_size(int n, int k, int part_l=0, int part_r=-1)
Generates a random partition with fixed size of a number.
uint64_t prime_from(uint64_t l)
Computes smallest prime from given value.
uint64_t gen_prime(uint64_t l, uint64_t r)
Generates a random prime in given range.
uint64_t gen_congruent(uint64_t l, uint64_t r, std::vector< uint64_t > rems, std::vector< uint64_t > mods)
Generates random number in range given modular congruences.
| std::vector< int > tgen::math::gen_partition |
( |
int | n, |
|
|
int | part_l = 1, |
|
|
int | part_r = -1 ) |
|
inline |
Generates a random partition of a number.
- Parameters
-
| n | Number to partition. |
| part_l | Minimum part value. |
| part_r | Maximum part value. |
- Precondition
- n > 0.
part_l > 0.
Partition is ordered (so technically a composition). That is, (1, 1, 2) != (1, 2, 1). If part_r = -1, part_r is considered to be n (unbounded).
- Returns
- A uniformly random ordered partition of n with values in [part_l, part_r].
- Exceptions
-
| std::runtime_error | if there is no such partition. |
- Note
- Distribution might be slighly biased because of floating point arithmetic.
Complexity
O(n).
Examples
auto part = tgen::math::partition(10, 2, 3);
Definition at line 1854 of file tgen.h.
| std::vector< int > tgen::math::gen_partition_fixed_size |
( |
int | n, |
|
|
int | k, |
|
|
int | part_l = 0, |
|
|
int | part_r = -1 ) |
|
inline |
Generates a random partition with fixed size of a number.
- Parameters
-
| n | Number to partition. |
| k | Number of parts. |
| part_l | Minimum part value. |
| part_r | Maximum part value. |
- Precondition
- n >= k > 0.
part_l >= 0.
Partition is ordered (so technically a composition). That is, (1, 1, 2) != (1, 2, 1). If part_r = -1, part_r is considered to be n (unbounded).
- Returns
- A uniformly random ordered partition of n with length k and values in [part_l, part_r].
- Exceptions
-
| std::runtime_error | if there is no such partition. |
- Note
- Distribution might be slighly biased because of floating point arithmetic.
Complexity
O(n) time/memory if part_r = -1;
O(n * k) time/memory otherwise.
Examples
auto part = tgen::math::partition_fixed_size(10, 4, 2, 3);
Definition at line 1917 of file tgen.h.