Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
check_varsigma_odd.cpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file common/check_varsigma_odd.cpp (January 5, 2018)
3  * \brief
4  * Check odd numbers for the varsigma_odd problem
5  * and print bad and perfect square numbers.
6  *
7  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
8  * http://www.opimedia.be/
9  */
10 
11 // \cond
12 #include <cstdlib>
13 
14 #include <chrono>
15 #include <iostream>
16 // \endcond
17 
18 #include "helper/helper.hpp"
19 #include "sigmaodd/primes.hpp"
20 #include "sigmaodd/sigmaodd.hpp"
21 
22 
23 
24 /* ***********
25  * Prototype *
26  *************/
27 
28 void
30 
31 
32 
33 /* **********
34  * Function *
35  ************/
36 
37 void
39  std::cerr << "Usage: check_varsigma_odd [options]" << std::endl
40  << std::endl
41  << "Options:" << std::endl
42  << " --first n first odd number to check (3 by default)" << std::endl
43  << " --last n last odd 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 = 3;
66  sigmaodd::nat_type last = 101;
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(3ul, helper::get_ulong(argc, argv, ++i, &help_and_exit));
75  if (sigmaodd::is_even(first)) {
76  ++first;
77  }
78  }
79  else if (param == "--last") {
80  last = helper::get_ulong(argc, argv, ++i, &help_and_exit);
81  if (sigmaodd::is_even(last)) {
82  --last;
83  }
84  }
85  else if (param == "--nb") {
86  last = first + helper::get_ulong(argc, argv, ++i, &help_and_exit)*2 - 1;
87  }
88  else {
89  help_and_exit();
90  }
91  }
92 
93 
94  // Print intern configuration
96 
97  // Print parameters
98  std::cout << "First: " << first
99  << "\tLast: " << last
100  << "\tNb: " << (first <= last
101  ? (last - first)/2 + 1
102  : 0)
103  << std::endl;
104 
105  // Print table legend
106  std::cout << std::endl
107  << "n\tLower\tLength" << std::endl;
108  std::cout.flush();
109 
110 
111  // Main calculation
112  const std::chrono::steady_clock::time_point clock_start = std::chrono::steady_clock::now();
113 
114  sigmaodd::check_varsigma_odd(first, last);
115 
116  // End
117  std::chrono::duration<double> duration = std::chrono::steady_clock::now() - clock_start;
118 
119  std::cout << "Total duration: " << helper::duration_to_string(duration)
120  << std::endl;
121 
122  return EXIT_SUCCESS;
123 }
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
void help_and_exit()
constexpr bool is_even(nat_type n)
Return true iff n is even.
std::string duration_to_string(std::chrono::duration< double > duration_second)
Return a string with the duration expressed in milliseconds, seconds, minutes and hours...
Definition: helper.cpp:61
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
Functions to access to tables of precaculated prime numbers and offsets to iterate on possible prime ...
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
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
int main(int argc, const char *const argv[])