16 #include "../helper/helper.hpp" 27 const nat_type array_potential_prime_offsets_[array_potential_prime_offsets_nb_] = {
28 10, 2, 4, 2, 4, 6, 2, 6, 4, 2,
29 4, 6, 6, 2, 6, 4, 2, 6, 4, 6,
30 8, 4, 2, 4, 2, 4, 8, 6, 4, 6,
31 2, 4, 6, 2, 6, 6, 4, 2, 4, 6,
32 2, 6, 4, 2, 4, 2, 10, 2};
45 #include "primes_table16.txt" 57 std::vector<FactorExp>
65 std::vector<FactorExp> list;
72 if (n_exp.second > 0) {
73 list.push_back({2, n_exp.second});
79 while (*(++p) <= sqrt_n) {
82 unsigned int alpha = 0;
90 list.push_back({*p, alpha});
97 list.push_back({n, 1});
109 n *=
pow_nat(prime_exp.factor, prime_exp.exp);
121 nu *= prime_exp.exp + 1;
133 if (prime_exp.factor != 2) {
134 nu *= prime_exp.exp + 1;
159 if (prime_exp.factor != 2) {
187 else if (prime > sqrt_n) {
199 for (
unsigned int i = 0; i < potential_prime_offsets_table_nb(); ++i) {
200 p += potential_prime_offsets_table_by_index(i);
216 assert(
sizeof(int32_t) ==
sizeof(
prime_type));
223 [](
const void *ptr_a,
const void *ptr_b) ->
int {
242 if (array_odd_primes_ !=
nullptr) {
243 free(array_odd_primes_);
244 array_odd_primes_ =
nullptr;
254 for (
unsigned int i = 0; i < 5; ++i) {
268 array_odd_primes_ =
reinterpret_cast<prime_type*
>(malloc(size));
270 if (array_odd_primes_ ==
nullptr) {
274 std::ifstream infile(filename, std::ios::in | std::ios::binary);
276 infile.read(reinterpret_cast<char*>(array_odd_primes_), 4);
277 infile.read(reinterpret_cast<char*>(array_odd_primes_), size);
283 free(array_odd_primes_);
284 array_odd_primes_ =
nullptr;
287 return (array_odd_primes_ !=
nullptr);
unsigned long nat_type
Type for natural number used in all code, on 64 bits.
constexpr nat_type sum_geometric_progression_strict(nat_type r, unsigned int k)
Return sum_geometric_progression(r, k) but only for r > 1.
nat_type floor_square_root(nat_type n)
Return the square root of n rounded to below.
uint64_t nat_type
Type for natural number used in all code, on 64 bits.
Structure to represent a factor with its exponent.
prime_type odd_primes_table_last()
Return the last odd prime number in the precalculated table.
nat_type factorization_to_nu_odd(std::vector< FactorExp > prime_exps)
Return the number of odd divisors of the number corresponding to the factorization.
const std::string prime_filename
Default filename for the binary file "big_data/prime28.bin".
bool is_prime(nat_type n)
Return true iff n is a prime number.
std::pair< nat_type, unsigned int > divide_until_odd_nb(nat_type n)
Divide n by 2 until the result is odd, and return (result, number of divisions).
constexpr bool is_even(nat_type n)
Return true iff n is even.
uint32_t prime_type
Type for prime number, particularly for the table of primes.
bool read_primes_table()
Read the binary file prime_filename to fill the table with all primes < 2^28. This table must be read...
A lot of functions and stuffs to deal the sigma_odd problem and related stuffs.
constexpr nat_type MAX_POSSIBLE_N
Lower bound of the bigger number such that it is possible to compute the result of the sigma function...
bool is_file_exists(std::string filename)
Return true iff the file (or directory) exists.
constexpr bool is_divide(nat_type d, nat_type n)
Return true iff d divide n, i.e. if n is divisible by d.
constexpr nat_type pow_nat(nat_type n, unsigned int k)
Return x^k, x power k.
Functions to access to tables of precaculated prime numbers and offsets to iterate on possible prime ...
bool is_prime_in_odd_primes_table(nat_type n)
Return true iff n is a prime number present in the precalculated table.
const prime_type * odd_primes_table_ptr()
Return a pointer to the first number in the precalculated table.
std::vector< FactorExp > factorize(nat_type n)
Return a list of prime factors with their exponents.
nat_type factorization_to_n(std::vector< FactorExp > prime_exps)
Return the number corresponding to the factorization.
prime_type odd_primes_table_by_index(unsigned int i)
Return the (i + 1)th odd prime number from the precalculated table.
std::string concat_path(std::string path1, std::string path2)
Return the path composed by path1/path2.
nat_type factorization_to_sigma_odd(std::vector< FactorExp > prime_exps)
Return the sum of odd divisors of the number corresponding to the factorization.
nat_type factorization_to_sigma(std::vector< FactorExp > prime_exps)
Return the sum of all divisors of the number corresponding to the factorization.
constexpr unsigned int array_odd_primes_nb_
Number of odd prime numbers in the table array_odd_primes_.
constexpr unsigned int odd_primes_table_nb()
Return the number of odd prime numbers in the precalculated table.
nat_type factorization_to_nu(std::vector< FactorExp > prime_exps)
Return the number of all divisors of the number corresponding to the factorization.
prime_type * array_odd_primes_
Array of all odd prime numbers < 2^28 with a final 0. (Or < 2^16 if the macro PRIME16 is defined...