17 #include "../helper/helper.hpp" 44 nat_type result,
unsigned int length,
64 std::cout << std::endl
65 <<
"! Found not trivial cycle " 66 << start_n <<
'\t' << length <<
'\t' << n << std::endl;
76 std::cout << std::endl
77 <<
"! Impossible to check " 78 << start_n <<
'\t' << length <<
'\t' << n << std::endl;
89 return static_cast<double>(n*100) / static_cast<double>(d);
95 nat_type result,
unsigned int length,
97 if (!print_only_longer || (length > 1)) {
98 std::cout << n <<
'\t' 103 std::cout <<
' ' << (length == 2
108 if (print_path && (n > 1)) {
112 std::cout << std::endl;
121 for (
unsigned int i = 0; i < 4; ++i) {
127 std::cout << std::endl
128 <<
"# length 1: " << lengths[0]
129 <<
" \t= " <<
percent_(lengths[0], nb) <<
'%' << std::endl
130 <<
"# length 2: " << lengths[1]
131 <<
" \t= " <<
percent_(lengths[1], nb) <<
'%' << std::endl
132 <<
"# length 3: " << lengths[2]
133 <<
" \t= " <<
percent_(lengths[2], nb) <<
'%' << std::endl
134 <<
"# length > 3: " << lengths[3]
135 <<
" \t= " <<
percent_(lengths[3], nb) <<
'%' << std::endl;
141 std::cout <<
'\t' << n;
148 std::cout << ' ' << (value > new_value
152 :
'=')) <<
' ' << new_value;
165 assert(first_n >= 3);
168 for (
nat_type start_n = first_n; start_n <= last_n; start_n += 2) {
174 unsigned int length = 0;
180 }
while (n > start_n);
185 std::cout << start_n <<
'\t' << length <<
'\t' << n << std::endl;
198 for (
unsigned int i = 1; i < path.size(); ++i) {
199 s += (path[i -1] > path[i]
201 : (path[i -1] < path[i]
217 for (
nat_type start_n = first; start_n <= last; start_n += 2) {
225 std::cout <<
"! Found not trivial cycle " 226 << start_n <<
'\t' << n << std::endl;
230 else if (n > start_n) {
231 std::cout << start_n;
232 for (
unsigned int d = 3; d <= 9; d += 2) {
234 std::cout <<
" !" << d;
243 std::cout << std::endl;
251 print_path(
const std::vector<nat_type> &path, std::ostream &out) {
252 assert(!path.empty());
253 assert(path.back() == 1);
260 print_path(
const std::vector<nat_type>::const_iterator &path_begin,
261 const std::vector<nat_type>::const_iterator &path_end,
263 if (path_begin != path_end) {
264 std::vector<nat_type>::const_iterator it = path_begin;
267 for ( ; it + 1 != path_end; ++it) {
268 out << ' ' << (*it > *(it + 1)
272 :
'=')) <<
' ' << *(it + 1);
287 assert(!path.empty());
290 const unsigned int length =
static_cast<unsigned int>(path.size() - 1);
291 const std::vector<nat_type>::const_iterator lower_cit
292 = std::find_if(path.cbegin(), path.cend(),
293 [n] (
const nat_type &x) {
return x < n; });
294 const unsigned int partial_length
295 =
static_cast<unsigned int>(lower_cit - path.cbegin());
297 const bool is_bad =
is_odd(n) && !is_square && (partial_length > 1);
300 || (print_bad && is_bad)) {
301 assert(lower_cit != path.cend());
309 if (print_category) {
310 std::cout <<
'\t' << (
is_even(n)
324 std::cout <<
'\t' << *lower_cit;
327 std::cout <<
'\t' << partial_length;
339 if (partial_length != length) {
340 assert(path.back() == 1);
343 std::cout <<
'\t' << length;
351 std::cout << std::endl;
364 for (
nat_type n = first; n <= last; n += 2) {
365 const std::pair<nat_type, unsigned int> result_length =
368 assert(result_length.second > 0);
370 ++lengths[std::min(4u, result_length.second) - 1];
373 result_length.first, result_length.second,
374 print_only_longer, print_path);
389 for (
nat_type n = first; n <= last; n += 2) {
390 const std::pair<nat_type, unsigned int> result_length =
393 assert(result_length.second > 0);
395 ++lengths[std::min(4u, result_length.second) - 1];
398 result_length.first, result_length.second,
399 print_only_longer, print_path);
414 for (
nat_type n = first; n <= last; n += 2) {
415 const std::pair<nat_type, unsigned int> result_length =
418 assert(result_length.second > 0);
420 ++lengths[std::min(4u, result_length.second) - 1];
423 result_length.first, result_length.second,
424 print_only_longer, print_path);
438 while (
square(i_first) < first) {
444 for (
nat_type i = i_first; i <= i_last; i += 2) {
449 std::cout <<
"! Found not trivial cycle " 450 << start_n <<
'\t' << n << std::endl;
455 std::cout << start_n <<
'\t' << n << (
is_square(n)
461 std::cout << std::endl;
484 if (!skip_primes_table) {
489 if (prime > sqrt_n) {
493 unsigned int alpha = 0;
511 static_cast<unsigned int>(std::rand()) % n,
521 if (!coprimes.empty()) {
522 for (
const FactorExp factor_exp : coprimes) {
535 assert(p % potential_prime_offsets_table_modulo() == 1);
538 for (
unsigned int i = 0; i < potential_prime_offsets_table_nb(); ++i) {
539 p += potential_prime_offsets_table_by_index(i);
545 unsigned int alpha = 0;
578 if (prime > sqrt_n) {
582 unsigned int alpha = 0;
592 if (prime > sqrt_n) {
598 if ((n != start_n) && (++nb > 1000)) {
605 if (bound < start_n) {
615 static_cast<unsigned int>(std::rand()) % n,
625 if (!coprimes.empty()) {
626 for (
const FactorExp factor_exp : coprimes) {
639 assert(p % potential_prime_offsets_table_modulo() == 1);
642 for (
unsigned int i = 0; i < potential_prime_offsets_table_nb(); ++i) {
643 p += potential_prime_offsets_table_by_index(i);
649 unsigned int alpha = 0;
665 if ((n != start_n) && (++nb > 1000)) {
672 if (bound < start_n) {
692 std::pair<nat_type, unsigned int>
697 unsigned int length = 0;
703 }
while (n > start_n);
707 return std::make_pair(n, length);
711 std::pair<nat_type, unsigned int>
716 unsigned int length = 0;
722 }
while (n > start_n);
726 return std::make_pair(n, length);
730 std::pair<nat_type, unsigned int>
735 unsigned int length = 0;
741 }
while (n > start_n);
745 return std::make_pair(n, length);
749 std::pair<nat_type, unsigned int>
754 unsigned int length = 0;
760 }
while (n > start_n);
764 return std::make_pair(n, length);
779 if (prime > sqrt_n) {
783 unsigned int alpha = 0;
804 assert(n >= potential_prime_offsets_table_modulo());
813 static_cast<unsigned int>(std::rand()) % n,
823 if (!coprimes.empty()) {
824 for (
const FactorExp factor_exp : coprimes) {
837 assert(p % potential_prime_offsets_table_modulo() == 1);
840 for (
unsigned int i = 0; i < potential_prime_offsets_table_nb(); ++i) {
841 p += potential_prime_offsets_table_by_index(i);
847 unsigned int alpha = 0;
unsigned long nat_type
Type for natural number used in all code, on 64 bits.
nat_type sum_odd_divisors__naive(nat_type n)
Calculates the sum of odd divisors of n by the naive method and returns it.
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.
void exit_if_impossible_to_check_(nat_type start_n, unsigned int length, nat_type n)
void print_path_infos(const std::vector< nat_type > &path, bool print_bad, bool print_all, bool print_category, bool print_lower, bool print_length, bool print_path, std::ostream &out)
Send (if the below condition is true) to the stream a string representation of the path with some inf...
constexpr bool is_odd(nat_type n)
Return true iff n is odd.
std::pair< nat_type, unsigned int > sum_odd_divisors_divided_until_odd_iterate_until_lower__factorize(nat_type n)
Iterates the sum_odd_divisors_divided_until_odd__factorize() function from n until have a result lowe...
Functions to calculate pentagonal numbers and one useless algorithm that used the Euler formula to ca...
void print_sigmaodd__naive(nat_type first, nat_type last, bool print_only_longer, bool print_path)
Iterate from first to last (included) and print result of the sum_odd_divisors_divided_until_odd_iter...
std::pair< nat_type, unsigned int > sum_odd_divisors_divided_until_odd_iterate_until_lower__factorize_bound(nat_type n)
Iterates the sum_odd_divisors_divided_until_odd__factorize() function from n until have a result lowe...
nat_type sum_odd_divisors_divided_until_odd__factorize(nat_type n, bool skip_primes_table)
Calculates the sum of all odd divisors of n by the factorization method, divides the results by 2 unt...
void print_path_(nat_type n)
nat_type divide_until_odd(nat_type n)
Return n divided by 2 until the result is odd.
constexpr bool is_even(nat_type n)
Return true iff n is even.
void print_sigmaodd__factorize_bound(nat_type first, nat_type last, bool print_only_longer, bool print_path)
Iterate from first to last (included) and print result of the sum_odd_divisors_divided_until_odd_iter...
bool is_square(nat_type n)
Return true iff n is a perfect square.
std::pair< nat_type, unsigned int > sum_odd_divisors_divided_until_odd_iterate_until_lower__euler(nat_type n)
Iterates the sum_odd_divisors_divided_until_odd__euler() function from n until have a result lower th...
A lot of functions and stuffs to deal the sigma_odd problem and related stuffs.
void print_square(nat_type first, nat_type last, bool print_path)
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...
void exit_if_found_exception_(nat_type start_n, unsigned int length, nat_type n)
constexpr bool is_divide(nat_type d, nat_type n)
Return true iff d divide n, i.e. if n is divisible by d.
nat_type varsum_odd(nat_type n)
Calculates the sum of all odd divisors of n by the factorization method, divides the results by 2 unt...
Functions to access to tables of precaculated prime numbers and offsets to iterate on possible prime ...
void print_data_(nat_type n, nat_type result, unsigned int length, bool print_only_longer, bool print_path)
void check_varsigma_odd(nat_type first_n, nat_type last_n)
Iterate from first to last (included) and for each odd n such that is_little_mersenne_prime_unitary_d...
std::pair< nat_type, unsigned int > sum_odd_divisors_divided_until_odd_iterate_until_lower__naive(nat_type n)
Iterates the sum_odd_divisors_divided_until_odd__naive() function from n until have a result lower th...
nat_type sum_odd_divisors_divided_until_odd__naive(nat_type n)
Calculates the sum of all odd divisors of n by the naive method, divides the results by 2 until becom...
void print_long(nat_type first, nat_type last, bool print_path)
Iterate from first to last (included) and for each odd n not square such that is_little_mersenne_prim...
double percent_(nat_type n, nat_type d)
void print_sigmaodd__factorize(nat_type first, nat_type last, bool print_only_longer, bool print_path)
Iterate from first to last (included) and print result of the sum_odd_divisors_divided_until_odd_iter...
nat_type sum_odd_divisors_divided_until_odd__factorize_bound(nat_type n, nat_type start_n)
Calculates the sum of all odd divisors of n by the factorization method, divides the results by 2 unt...
prime_type odd_primes_table_by_index(unsigned int i)
Return the (i + 1)th odd prime number from the precalculated table.
nat_type sum_divisors__euler(nat_type n)
Calculates the sum of all divisors of n with the Euler formula about pentagonal numbers and returns i...
std::vector< FactorExp > coprime_factor_exps(nat_type a, nat_type b)
Heuristic to return a list of factors with their exponents such that all factors are coprimes and the...
void print_path(const std::vector< nat_type > &path, std::ostream &out)
Send to the stream a string representation of the path. All numbers are separated by the correspondin...
constexpr unsigned int odd_primes_table_nb()
Return the number of odd prime numbers in the precalculated table.
constexpr bool is_little_mersenne_prime_unitary_divide(nat_type n)
Return true iff at least one of 3, 7, 31, 127, 8191, 131071 or 524287 is an unitary divisor of n...
nat_type varsum_odd_big(nat_type n, nat_type sqrt_n)
Calculates the sum of all odd divisors of n by the factorization method, divides the results by 2 unt...
Main functions to deal the sigma_odd problem.
constexpr double square(double x)
Return x*x.
nat_type sum_odd_divisors_divided_until_odd__euler(nat_type n)
Calculates the sum of all odd divisors of n by the Euler formula method, divides the results by 2 unt...
std::string path_to_string(const std::vector< nat_type > &path)
std::string to_string(bool b)
Return the string "true" if b, else "false".
void print_lengths_(nat_type lengths[])
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.
nat_type pollard_rho(nat_type n)
Return pollard_rho(n, rand() % n, floor square root of n).