Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
sigmaodd.cpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file common/sigmaodd/sigmaodd.cpp (January 17, 2018)
3  *
4  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
5  * http://www.opimedia.be/
6  */
7 
8 // \cond
9 #include <cmath>
10 #include <cstdlib>
11 
12 #include <algorithm>
13 #include <iostream>
14 #include <vector>
15 // \endcond
16 
17 #include "../helper/helper.hpp"
18 #include "pentagonal.hpp"
19 #include "primes.hpp"
20 
21 #include "sigmaodd.hpp"
22 
23 
24 namespace sigmaodd {
25 
26  /* ********************
27  * Private prototypes *
28  **********************/
29 
30  void
31  exit_if_found_exception_(nat_type start_n, unsigned int length, nat_type n);
32 
33 
34  void
35  exit_if_impossible_to_check_(nat_type start_n, unsigned int length, nat_type n);
36 
37 
38  double
40 
41 
42  void
44  nat_type result, unsigned int length,
45  bool print_only_longer, bool print_path);
46 
47 
48  void
49  print_lengths_(nat_type lengths[]);
50 
51 
52  void
54 
55 
56 
57  /* *******************
58  * Private functions *
59  *********************/
60 
61  void
62  exit_if_found_exception_(nat_type start_n, unsigned int length, nat_type n) {
63  if (n == start_n) {
64  std::cout << std::endl
65  << "! Found not trivial cycle "
66  << start_n << '\t' << length << '\t' << n << std::endl;
67 
68  exit(EXIT_FAILURE);
69  }
70  }
71 
72 
73  void
74  exit_if_impossible_to_check_(nat_type start_n, unsigned int length, nat_type n) {
75  if (n > MAX_POSSIBLE_N) {
76  std::cout << std::endl
77  << "! Impossible to check "
78  << start_n << '\t' << length << '\t' << n << std::endl;
79 
80  exit(EXIT_FAILURE);
81  }
82  }
83 
84 
85  double
87  assert(d != 0);
88 
89  return static_cast<double>(n*100) / static_cast<double>(d);
90  }
91 
92 
93  void
95  nat_type result, unsigned int length,
96  bool print_only_longer, bool print_path) {
97  if (!print_only_longer || (length > 1)) {
98  std::cout << n << '\t'
99  << result << '\t'
100  << length;
101 
102  if (length > 1) {
103  std::cout << ' ' << (length == 2
104  ? '*'
105  : '#');
106  }
107 
108  if (print_path && (n > 1)) {
109  print_path_(n);
110  }
111 
112  std::cout << std::endl;
113  }
114  }
115 
116 
117  void
119  nat_type nb = 0;
120 
121  for (unsigned int i = 0; i < 4; ++i) {
122  nb += lengths[i];
123  }
124 
125  assert(nb != 0);
126 
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;
136  }
137 
138 
139  void
141  std::cout << '\t' << n;
142 
143  nat_type value = n;
144 
145  while (value > 1) {
147 
148  std::cout << ' ' << (value > new_value
149  ? '>'
150  : (value < new_value
151  ? '<'
152  : '=')) << ' ' << new_value;
153  value = new_value;
154  }
155  }
156 
157 
158 
159  /* ***********
160  * Functions *
161  *************/
162 
163  void
165  assert(first_n >= 3);
166  assert(is_odd(first_n));
167 
168  for (nat_type start_n = first_n; start_n <= last_n; start_n += 2) {
170  continue;
171  }
172 
173  nat_type n = start_n;
174  unsigned int length = 0;
175 
176  do {
177  ++length;
178  n = varsum_odd(n);
179  exit_if_impossible_to_check_(start_n, length, n);
180  } while (n > start_n);
181 
182  exit_if_found_exception_(start_n, length, n);
183 
184  if (length > 1) {
185  std::cout << start_n << '\t' << length << '\t' << n << std::endl;
186  std::cout.flush();
187  }
188  }
189  }
190 
191 
192  std::string
193  path_to_string(const std::vector<nat_type> &path) {
194  std::string s;
195 
196  if (!path.empty()) {
197  s += std::to_string(path[0]);
198  for (unsigned int i = 1; i < path.size(); ++i) {
199  s += (path[i -1] > path[i]
200  ? " > "
201  : (path[i -1] < path[i]
202  ? " < "
203  : " = "));
204  s += std::to_string(path[i]);
205  }
206  }
207 
208  return s;
209  }
210 
211 
212  void
213  print_long(nat_type first, nat_type last, bool print_path) {
214  assert(first >= 3);
215  assert(is_odd(first));
216 
217  for (nat_type start_n = first; start_n <= last; start_n += 2) {
218  if (is_little_mersenne_prime_unitary_divide(start_n) || is_square(start_n)) {
219  continue;
220  }
221 
222  const nat_type n = varsum_odd(start_n);
223 
224  if (n == start_n) {
225  std::cout << "! Found not trivial cycle "
226  << start_n << '\t' << n << std::endl;
227 
228  exit(EXIT_FAILURE);
229  }
230  else if (n > start_n) {
231  std::cout << start_n;
232  for (unsigned int d = 3; d <= 9; d += 2) {
233  if (!is_divide(d, start_n)) {
234  std::cout << " !" << d;
235  }
236  }
237  std::cout << '\t' << n << (is_square(n)
238  ? " #"
239  : "");
240  if (print_path) {
241  print_path_(start_n);
242  }
243  std::cout << std::endl;
244  std::cout.flush();
245  }
246  }
247  }
248 
249 
250  void
251  print_path(const std::vector<nat_type> &path, std::ostream &out) {
252  assert(!path.empty());
253  assert(path.back() == 1);
254 
255  print_path(path.cbegin(), path.cend(), out);
256  }
257 
258 
259  void
260  print_path(const std::vector<nat_type>::const_iterator &path_begin,
261  const std::vector<nat_type>::const_iterator &path_end,
262  std::ostream &out) {
263  if (path_begin != path_end) {
264  std::vector<nat_type>::const_iterator it = path_begin;
265 
266  out << *it;
267  for ( ; it + 1 != path_end; ++it) {
268  out << ' ' << (*it > *(it + 1)
269  ? '>'
270  : (*it < *(it + 1)
271  ? '<'
272  : '=')) << ' ' << *(it + 1);
273  }
274  }
275  }
276 
277 
278  void
279  print_path_infos(const std::vector<nat_type> &path,
280  bool print_bad,
281  bool print_all,
282  bool print_category,
283  bool print_lower,
284  bool print_length,
285  bool print_path,
286  std::ostream &out) {
287  assert(!path.empty());
288 
289  const nat_type n = path.front();
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());
296  const bool is_square = sigmaodd::is_square(n);
297  const bool is_bad = is_odd(n) && !is_square && (partial_length > 1);
298 
299  if (print_all
300  || (print_bad && is_bad)) {
301  assert(lower_cit != path.cend());
302 
303  std::cout << n;
304  if (is_bad && !is_divide(9, n)) {
305  // Exception for specific conjecture about the divisibility of bad numbers
306  std::cout << " *";
307  }
308 
309  if (print_category) {
310  std::cout << '\t' << (is_even(n)
311  ? 'E'
312  : (n == path.back()
313  ? 'F'
314  : (is_square
315  ? 'S'
316  : (is_bad
317  ? 'B'
318  : 'G'))));
319  }
320 
321 
322  // Partial path
323  if (print_lower) {
324  std::cout << '\t' << *lower_cit;
325  }
326  if (print_length) {
327  std::cout << '\t' << partial_length;
328  if (length > n) { // exception for specific conjecture about the length
329  std::cout << " *";
330  }
331  }
332  if (print_path) {
333  std::cout << '\t';
334  sigmaodd::print_path(path.cbegin(), lower_cit + 1, out);
335  }
336 
337 
338  // Complete path
339  if (partial_length != length) {
340  assert(path.back() == 1);
341 
342  if (print_length) {
343  std::cout << '\t' << length;
344  }
345  if (print_path) {
346  std::cout << '\t';
347  sigmaodd::print_path(path, out);
348  }
349  }
350 
351  std::cout << std::endl;
352  }
353  }
354 
355 
356  void
358  bool print_only_longer, bool print_path) {
359  assert(first >= 3);
360  assert(is_odd(first));
361 
362  nat_type lengths[4] = {0, 0, 0, 0};
363 
364  for (nat_type n = first; n <= last; n += 2) {
365  const std::pair<nat_type, unsigned int> result_length =
367 
368  assert(result_length.second > 0);
369 
370  ++lengths[std::min(4u, result_length.second) - 1];
371 
372  print_data_(n,
373  result_length.first, result_length.second,
374  print_only_longer, print_path);
375  }
376 
377  print_lengths_(lengths);
378  }
379 
380 
381  void
383  bool print_only_longer, bool print_path) {
384  assert(first >= 3);
385  assert(is_odd(first));
386 
387  nat_type lengths[4] = {0, 0, 0, 0};
388 
389  for (nat_type n = first; n <= last; n += 2) {
390  const std::pair<nat_type, unsigned int> result_length =
392 
393  assert(result_length.second > 0);
394 
395  ++lengths[std::min(4u, result_length.second) - 1];
396 
397  print_data_(n,
398  result_length.first, result_length.second,
399  print_only_longer, print_path);
400  }
401 
402  print_lengths_(lengths);
403  }
404 
405 
406  void
408  bool print_only_longer, bool print_path) {
409  assert(first >= 3);
410  assert(is_odd(first));
411 
412  nat_type lengths[4] = {0, 0, 0, 0};
413 
414  for (nat_type n = first; n <= last; n += 2) {
415  const std::pair<nat_type, unsigned int> result_length =
417 
418  assert(result_length.second > 0);
419 
420  ++lengths[std::min(4u, result_length.second) - 1];
421 
422  print_data_(n,
423  result_length.first, result_length.second,
424  print_only_longer, print_path);
425  }
426 
427  print_lengths_(lengths);
428  }
429 
430 
431  void
433  assert(first >= 3);
434  assert(is_odd(first));
435 
436  nat_type i_first = floor_square_root(first);
437 
438  while (square(i_first) < first) {
439  i_first += 2;
440  }
441 
442  const nat_type i_last = floor_square_root(last);
443 
444  for (nat_type i = i_first; i <= i_last; i += 2) {
445  const nat_type start_n = square(i);
446  const nat_type n = varsum_odd(start_n);
447 
448  if (n == start_n) {
449  std::cout << "! Found not trivial cycle "
450  << start_n << '\t' << n << std::endl;
451 
452  exit(EXIT_FAILURE);
453  }
454 
455  std::cout << start_n << '\t' << n << (is_square(n)
456  ? " #"
457  : "");
458  if (print_path) {
459  print_path_(start_n);
460  }
461  std::cout << std::endl;
462  std::cout.flush();
463  }
464  }
465 
466 
467  nat_type
469  assert(n != 0);
470 
472  }
473 
474 
475  nat_type
477  assert(n != 0);
478 
479  n = divide_until_odd(n);
480 
481  nat_type sum = 1;
482  nat_type sqrt_n = floor_square_root(n);
483 
484  if (!skip_primes_table) {
485  // Search prime factors present in the precalculated table
486  for (unsigned int i = 0; (n > 1) && (i < odd_primes_table_nb()); ++i) {
487  const nat_type prime = odd_primes_table_by_index(i);
488 
489  if (prime > sqrt_n) { // remain n is prime
490  return sum*divide_until_odd(n + 1);
491  }
492 
493  unsigned int alpha = 0;
494 
495  while (is_divide(prime, n)) {
496  n /= prime;
497  ++alpha;
498  }
499 
500  if (alpha > 0) {
501  sqrt_n = floor_square_root(n);
503  }
504  }
505  }
506 
507  // Try to find a divisor by Pollard's rho heuristic
508  // and use it to try to find coprime factors.
509  {
510  const nat_type divisor = pollard_rho(n,
511  static_cast<unsigned int>(std::rand()) % n,
512  floor_square_root(sqrt_n));
513 
514  if (divisor != 0) {
515  assert(1 < divisor);
516  assert(divisor < n);
517  assert(is_divide(divisor, n));
518 
519  const std::vector<FactorExp> coprimes = coprime_factor_exps(divisor, n/divisor);
520 
521  if (!coprimes.empty()) {
522  for (const FactorExp factor_exp : coprimes) {
523  sum *= sum_odd_divisors_divided_until_odd__factorize(factor_exp.value(), true);
524  }
525 
526  return sum;
527  }
528  }
529  }
530 
531 #ifdef PRIME16
532  // Search other prime factors by iteration on potential primes
534 
535  assert(p % potential_prime_offsets_table_modulo() == 1);
536 
537  while (n > 1) {
538  for (unsigned int i = 0; i < potential_prime_offsets_table_nb(); ++i) {
539  p += potential_prime_offsets_table_by_index(i);
540 
541  if (p > sqrt_n) { // remain n is prime
542  return sum*divide_until_odd(n + 1);
543  }
544 
545  unsigned int alpha = 0;
546 
547  while (is_divide(p, n)) {
548  n /= p;
549  ++alpha;
550  }
551 
552  if (alpha > 0) {
553  sqrt_n = floor_square_root(n);
555  }
556  }
557  }
558 #endif
559 
560  return sum;
561  }
562 
563 
564  nat_type
566  assert(n != 0);
567 
568  n = divide_until_odd(n);
569 
570  unsigned int nb = 0;
571  nat_type sum = 1;
572  nat_type sqrt_n = floor_square_root(n);
573 
574  // Search prime factors present in the precalculated table
575  for (unsigned int i = 0; (n > 1) && (i < odd_primes_table_nb()); ++i) {
576  const nat_type prime = odd_primes_table_by_index(i);
577 
578  if (prime > sqrt_n) { // remain n is prime
579  return sum*divide_until_odd(n + 1);
580  }
581 
582  unsigned int alpha = 0;
583 
584  while (is_divide(prime, n)) {
585  n /= prime;
586  ++alpha;
587  }
588 
589  if (alpha > 0) {
590  sqrt_n = floor_square_root(n);
592  if (prime > sqrt_n) { // remain n is prime
593  return sum*divide_until_odd(n + 1);
594  }
595  nb = 1000;
596  }
597 
598  if ((n != start_n) && (++nb > 1000)) {
599  assert(n < start_n);
600 
601  nb = 0;
602 
603  const nat_type bound = sum*sum_odd_divisors_upper_bound__DeTemple(n, prime);
604 
605  if (bound < start_n) {
606  return bound; // ???
607  }
608  }
609  }
610 
611  // Try to find a divisor by Pollard's rho heuristic
612  // and use it to try to find coprime factors.
613  {
614  const nat_type divisor = pollard_rho(n,
615  static_cast<unsigned int>(std::rand()) % n,
616  floor_square_root(sqrt_n));
617 
618  if (divisor != 0) {
619  assert(1 < divisor);
620  assert(divisor < n);
621  assert(is_divide(divisor, n));
622 
623  const std::vector<FactorExp> coprimes = coprime_factor_exps(divisor, n/divisor);
624 
625  if (!coprimes.empty()) {
626  for (const FactorExp factor_exp : coprimes) {
627  sum *= sum_odd_divisors_divided_until_odd__factorize(factor_exp.value(), true);
628  }
629 
630  return sum;
631  }
632  }
633  }
634 
635 #ifdef PRIME16
636  // Search other prime factors by iteration on potential primes
638 
639  assert(p % potential_prime_offsets_table_modulo() == 1);
640 
641  while (n > 1) {
642  for (unsigned int i = 0; i < potential_prime_offsets_table_nb(); ++i) {
643  p += potential_prime_offsets_table_by_index(i);
644 
645  if (p > sqrt_n) { // remain n is prime
646  return sum*divide_until_odd(n + 1);
647  }
648 
649  unsigned int alpha = 0;
650 
651  while (is_divide(p, n)) {
652  n /= p;
653  ++alpha;
654  }
655 
656  if (alpha > 0) {
657  sqrt_n = floor_square_root(n);
659  if (p > sqrt_n) { // remain n is prime ???
660  return sum*divide_until_odd(n + 1);
661  }
662  nb = 1000;
663  }
664 
665  if ((n != start_n) && (++nb > 1000)) {
666  assert(n < start_n);
667 
668  nb = 0;
669 
670  const nat_type bound = sum*sum_odd_divisors_upper_bound__DeTemple(n, p);
671 
672  if (bound < start_n) {
673  return bound; // ???
674  }
675  }
676  }
677  }
678 #endif
679 
680  return sum;
681  }
682 
683 
684  nat_type
686  assert(n != 0);
687 
689  }
690 
691 
692  std::pair<nat_type, unsigned int>
694  assert(n > 1);
695 
696  const nat_type start_n = n;
697  unsigned int length = 0;
698 
699  do {
700  ++length;
702  exit_if_impossible_to_check_(start_n, length, n);
703  } while (n > start_n);
704 
705  exit_if_found_exception_(start_n, length, n);
706 
707  return std::make_pair(n, length); // ??? swap params?
708  }
709 
710 
711  std::pair<nat_type, unsigned int>
713  assert(n > 1);
714 
715  const nat_type start_n = n;
716  unsigned int length = 0;
717 
718  do {
719  ++length;
721  exit_if_impossible_to_check_(start_n, length, n);
722  } while (n > start_n);
723 
724  exit_if_found_exception_(start_n, length, n);
725 
726  return std::make_pair(n, length); // ??? swap params?
727  }
728 
729 
730  std::pair<nat_type, unsigned int>
732  assert(n > 1);
733 
734  const nat_type start_n = n;
735  unsigned int length = 0;
736 
737  do {
738  ++length;
740  exit_if_impossible_to_check_(start_n, length, n);
741  } while (n > start_n);
742 
743  exit_if_found_exception_(start_n, length, n);
744 
745  return std::make_pair(n, length); // ??? swap params?
746  }
747 
748 
749  std::pair<nat_type, unsigned int>
751  assert(n > 1);
752 
753  const nat_type start_n = n;
754  unsigned int length = 0;
755 
756  do {
757  ++length;
759  exit_if_impossible_to_check_(start_n, length, n);
760  } while (n > start_n);
761 
762  exit_if_found_exception_(start_n, length, n);
763 
764  return std::make_pair(n, length); // ??? swap params?
765  }
766 
767 
768  nat_type
770  assert(is_odd(n));
771 
772  nat_type sum = 1;
773  nat_type sqrt_n = floor_square_root(n);
774 
775  // Search prime factors present in the precalculated table
776  for (unsigned int i = 0; i < odd_primes_table_nb(); ++i) {
777  const nat_type prime = odd_primes_table_by_index(i);
778 
779  if (prime > sqrt_n) { // remain n is prime
780  return sum*divide_until_odd(n + 1);
781  }
782 
783  unsigned int alpha = 0;
784 
785  while (is_divide(prime, n)) {
786  n /= prime;
787  ++alpha;
788  }
789 
790  if (alpha > 0) {
791  sqrt_n = floor_square_root(n);
793  }
794  }
795 
796  return sum*varsum_odd_big(n, sqrt_n);
797  }
798 
799 
800  nat_type
802  assert(is_odd(n));
803 #ifdef PRIME16
804  assert(n >= potential_prime_offsets_table_modulo());
805 #endif
806 
807  nat_type sum = 1;
808 
809  // Try to find a divisor by Pollard's rho heuristic
810  // and use it to try to find coprime factors.
811  {
812  const nat_type divisor = pollard_rho(n,
813  static_cast<unsigned int>(std::rand()) % n,
814  floor_square_root(sqrt_n));
815 
816  if (divisor != 0) {
817  assert(1 < divisor);
818  assert(divisor < n);
819  assert(is_divide(divisor, n));
820 
821  const std::vector<FactorExp> coprimes = coprime_factor_exps(divisor, n/divisor);
822 
823  if (!coprimes.empty()) {
824  for (const FactorExp factor_exp : coprimes) {
825  sum *= varsum_odd_big(factor_exp.value(), floor_square_root(factor_exp.value()));
826  }
827 
828  return sum;
829  }
830  }
831  }
832 
833 #ifdef PRIME16
834  // Search other prime factors by iteration on potential primes
836 
837  assert(p % potential_prime_offsets_table_modulo() == 1);
838 
839  while (n > 1) {
840  for (unsigned int i = 0; i < potential_prime_offsets_table_nb(); ++i) {
841  p += potential_prime_offsets_table_by_index(i);
842 
843  if (p > sqrt_n) { // remain n is prime
844  return sum*divide_until_odd(n + 1);
845  }
846 
847  unsigned int alpha = 0;
848 
849  while (is_divide(p, n)) {
850  n /= p;
851  ++alpha;
852  }
853 
854  if (alpha > 0) {
855  sqrt_n = floor_square_root(n);
857  }
858  }
859  }
860 #endif
861 
862  return sum;
863  }
864 
865 } // namespace sigmaodd
unsigned long nat_type
Type for natural number used in all code, on 64 bits.
Definition: sigmaodd.cl:22
nat_type sum_odd_divisors__naive(nat_type n)
Calculates the sum of odd divisors of n by the naive method and returns it.
Definition: divisors.cpp:507
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.
Definition: helper.cpp:76
uint64_t nat_type
Type for natural number used in all code, on 64 bits.
Definition: helper.hpp:33
Structure to represent a factor with its exponent.
Definition: divisors.hpp:33
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)
Definition: sigmaodd.cpp:74
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...
Definition: sigmaodd.cpp:279
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...
Definition: sigmaodd.cpp:712
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...
Definition: sigmaodd.cpp:407
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...
Definition: sigmaodd.cpp:731
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...
Definition: sigmaodd.cpp:476
void print_path_(nat_type n)
Definition: sigmaodd.cpp:140
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...
Definition: sigmaodd.cpp:382
bool is_square(nat_type n)
Return true iff n is a perfect square.
Definition: divisors.cpp:267
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...
Definition: sigmaodd.cpp:693
A lot of functions and stuffs to deal the sigma_odd problem and related stuffs.
Definition: divisors.cpp:22
void print_square(nat_type first, nat_type last, bool print_path)
Definition: sigmaodd.cpp:432
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...
Definition: helper.hpp:54
void exit_if_found_exception_(nat_type start_n, unsigned int length, nat_type n)
Definition: sigmaodd.cpp:62
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...
Definition: sigmaodd.cpp:769
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)
Definition: sigmaodd.cpp:94
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...
Definition: sigmaodd.cpp:164
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...
Definition: sigmaodd.cpp:750
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...
Definition: sigmaodd.cpp:685
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...
Definition: sigmaodd.cpp:213
double percent_(nat_type n, nat_type d)
Definition: sigmaodd.cpp:86
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...
Definition: sigmaodd.cpp:357
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...
Definition: sigmaodd.cpp:565
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...
Definition: pentagonal.cpp:70
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...
Definition: divisors.cpp:162
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...
Definition: sigmaodd.cpp:251
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...
Definition: sigmaodd.cpp:801
Main functions to deal the sigma_odd problem.
constexpr double square(double x)
Return x*x.
const double alpha
Definition: harmonic.cpp:24
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...
Definition: sigmaodd.cpp:468
std::string path_to_string(const std::vector< nat_type > &path)
Definition: sigmaodd.cpp:193
std::string to_string(bool b)
Return the string "true" if b, else "false".
Definition: helper.cpp:177
void print_lengths_(nat_type lengths[])
Definition: sigmaodd.cpp:118
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.
Definition: divisors.cpp:602
nat_type pollard_rho(nat_type n)
Return pollard_rho(n, rand() % n, floor square root of n).
Definition: divisors.cpp:292