42 std::cerr <<
"Usage: table_harmonic [options]" << std::endl
44 <<
"Method options to calculate sum of divisors:" << std::endl
45 <<
" --bound factorize method with bound shortcuts (by default)" << std::endl
46 <<
" --factorize factorize number with partial prime numbers table" << std::endl
47 <<
" --naive try each odd possible divisor)" << std::endl
49 <<
"Options:" << std::endl
50 <<
" --first n first number to check (1 by default)" << std::endl
51 <<
" --last n last number to check (50 by default)" << std::endl
52 <<
" --nb n number of numbers to check" << std::endl;
64 main(
int argc,
const char*
const argv[]) {
73 enum Methods:
unsigned int {
factorize, factorize_bound, naive};
75 const std::string method_strings[3] = {
"factorize",
85 for (
unsigned int i = 1; i < static_cast<unsigned int>(argc); ++i) {
86 const std::string param(argv[i]);
88 if (param ==
"--bound") {
89 method = factorize_bound;
91 else if (param ==
"--factorize") {
94 else if (param ==
"--first") {
97 else if (param ==
"--last") {
100 else if (param ==
"--naive") {
103 else if (param ==
"--nb") {
113 std::cerr <<
"First: " << first
114 <<
"\tLast: " << last
115 <<
"\tNb: " << (first <= last
116 ? (last - first)/2 + 1
118 <<
"\tMethod: " << method_strings[method]
123 std::cout <<
"n\tsqrt\t|s_odd\tbound\tGUB\tDeTemp.\t|sum_o.\t|Half bound\tdiff h.\tfl.harm._odd\tharmonic_odd" 128 std::cout << std::fixed << std::setprecision(10);
139 else if (method == factorize_bound) {
142 else if (method == naive) {
155 * static_cast<double>(n)));
159 const double diff_half = (sqrt_n1 == 0
164 std::cout << n <<
'\t' 169 << bound_detemple <<
'\t' 177 assert(exact <= bound);
178 assert(exact <= gub_bound);
179 assert(exact <= bound_detemple);
181 assert(bound <= gub_bound);
182 assert(gub_bound <= bound_detemple);
184 assert(exact <= sum_odd_n);
185 if ((n != 2) && (n != 4)) {
186 assert(bound <= sum_odd_n);
nat_type sum_odd_divisors__naive(nat_type n)
Calculates the sum of odd divisors of n by the naive method and returns it.
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.
const std::string prime_filename
Default filename for the binary file "big_data/prime28.bin".
double diff_half_harmonic_upper_bound(nat_type a, nat_type b)
Return an upper bound of H_a - 1/2 H_b.
bool read_primes_table()
Read the binary file prime_filename to fill the table with all primes < 2^28. This table must be read...
Functions to access to tables of precaculated prime numbers and offsets to iterate on possible prime ...
nat_type sum_odd_divisors__factorize(nat_type n)
Calculates the sum of odd divisors of n by the factorization method and returns it.
Function to calculate harmonic number H_n = 1 + 1/2 + 1/3 + 1/4 + ... + 1/n and some variants and upp...
std::vector< FactorExp > factorize(nat_type n)
Return a list of prime factors with their exponents.
Some generic helper functions for programs.
nat_type sum_floor_n_harmonic_odd(nat_type n, nat_type to_n)
Return floor(n/1) + floor(n/3) + floor(n/5) + floor(n/7) + ... + (n/to_n or floor(1/(to_n-1))).
int main(int argc, const char *const argv[])
Main functions to deal the sigma_odd problem.
Functions in link with divisor notion: sum of divisors, factorization, GCD, coprime, ...
unsigned long get_ulong(int argc, const char *const argv[], unsigned int i, void(*help_and_exit_function)())
Return argv[i] converted in integer.
constexpr double harmonic_odd(nat_type n)
Return 1/1 + 1/3 + 1/5 + 1/7 + ... + (1/n or 1/(n-1)).
constexpr nat_type sum_odd(nat_type n)
Return 1 + 3 + 5 + 7 + ... + (n or n-1) = k^2 with k floor((n+1)/2).
nat_type sum_odd_divisors_upper_bound__DeTemple(nat_type n)
Return an upper bound of sum odd divisors of n using the DeTemple inequalities.