Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
table.cpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file common/table.cpp (January 5, 2018)
3  * \brief
4  * Print tables of sigma_odd results by several algorithms.
5  *
6  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
7  * http://www.opimedia.be/
8  */
9 
10 // \cond
11 #include <cassert>
12 #include <cmath>
13 #include <cstdlib>
14 
15 #include <iostream>
16 // \endcond
17 
18 #include "helper/helper.hpp"
19 #include "sigmaodd/helper.hpp"
20 #include "sigmaodd/primes.hpp"
21 #include "sigmaodd/sigmaodd.hpp"
22 
23 
24 /* ***********
25  * Prototype *
26  *************/
27 
28 void
30 
31 
32 
33 /* **********
34  * Function *
35  ************/
36 
37 void
39  std::cerr << "Usage: table [options]" << std::endl
40  << std::endl
41  << "Options:" << std::endl
42  << " --first n first number to check (1 by default)" << std::endl
43  << " --last n last number to check (101 by default)" << std::endl
44  << " --nb n number of odd numbers to check" << std::endl;
45 
46  exit(EXIT_FAILURE);
47 }
48 
49 
50 
51 /* ******
52  * Main *
53  ********/
54 
55 int
56 main(int argc, const char* const argv[]) {
57  // Load primes table
59  std::cerr << "! Impossible to load \"" << sigmaodd::prime_filename << '"' << std::endl
60  << std::endl;
61  help_and_exit();
62  }
63 
64 
65  sigmaodd::nat_type first = 1;
66  sigmaodd::nat_type last = 1000;
67 
68 
69  // Read command line parameters
70  for (unsigned int i = 1; i < static_cast<unsigned int>(argc); ++i) {
71  const std::string param(argv[i]);
72 
73  if (param == "--first") {
74  first = std::max(1ul, helper::get_ulong(argc, argv, ++i, &help_and_exit));
75  }
76  else if (param == "--last") {
77  last = helper::get_ulong(argc, argv, ++i, &help_and_exit);
78  }
79  else if (param == "--nb") {
80  last = first + helper::get_ulong(argc, argv, ++i, &help_and_exit)*2 - 1;
81  }
82  else {
83  help_and_exit();
84  }
85  }
86 
87 
88  // Print intern configuration
90 
91 
92  // Print parameters
93  std::cout << "First: " << first
94  << "\tLast: " << last
95  << "\tNb: " << (first <= last
96  ? last + 1 - first
97  : 0)
98  << std::endl;
99 
100 
101  // Print table legend
102  std::cout << std::endl
103  << "n\tsigma\tsigma_odd\tvarsigma_odd"
104  << std::endl;
105 
106 
107  // Print data
108  for (sigmaodd::nat_type n = first; n <= last; ++n) {
112 
113  std::cout << n
114  << '\t' << sum
115  << '\t' << sum_odd
116  << '\t' << varsum_odd
117  << std::endl;
118  }
119 
120  return EXIT_SUCCESS;
121 }
Define type and some generic functions.
uint64_t nat_type
Type for natural number used in all code, on 64 bits.
Definition: helper.hpp:33
const std::string prime_filename
Default filename for the binary file "big_data/prime28.bin".
Definition: primes.cpp:35
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
int main(int argc, const char *const argv[])
Definition: table.cpp:56
void help_and_exit()
Definition: table.cpp:38
bool read_primes_table()
Read the binary file prime_filename to fill the table with all primes < 2^28. This table must be read...
Definition: primes.cpp:241
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 ...
nat_type sum_odd_divisors__factorize(nat_type n)
Calculates the sum of odd divisors of n by the factorization method and returns it.
Definition: divisors.cpp:444
nat_type sum_divisors__factorize(nat_type n)
Calculates the sum of all divisors of n by the factorization method and returns it.
Definition: divisors.cpp:357
Some generic helper functions for programs.
void print_intern_config_compiler()
Print to stdcout the intern configuration of the compiler.
Definition: helper.cpp:148
Main functions to deal the sigma_odd problem.
unsigned long get_ulong(int argc, const char *const argv[], unsigned int i, void(*help_and_exit_function)())
Return argv[i] converted in integer.
Definition: helper.cpp:124
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).