Successive prime differences: Difference between revisions

m
C++ - renamed class
m (Minor edit to C++ code)
m (C++ - renamed class)
Line 144:
#include <cstdint>
#include <vector>
#include "sieve_of_eratosthenesprime_sieve.hhpp"
 
using integer = uint32_t;
Line 202:
const integer limit = 1000000;
const size_t max_group_size = 4;
sieve_of_eratosthenesprime_sieve sieve(limit);
diffs d[] = { {2}, {1}, {2, 2}, {2, 4}, {4, 2}, {6, 4, 2} };
vector group;
Line 221:
}</lang>
 
Contents of sieve_of_eratosthenesprime_sieve.hhpp:
<lang cpp>#ifndef SIEVE_OF_ERATOSTHENES_HPRIME_SIEVE_HPP
#define SIEVE_OF_ERATOSTHENES_HPRIME_SIEVE_HPP
 
#include <algorithm>
Line 232:
* See https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes.
*/
class sieve_of_eratosthenesprime_sieve {
public:
explicit sieve_of_eratosthenesprime_sieve(size_t);
bool is_prime(size_t) const;
private:
Line 245:
* @param limit the maximum integer that can be tested for primality
*/
inline sieve_of_eratosthenesprime_sieve::sieve_of_eratosthenesprime_sieve(size_t limit) {
limit = std::max(size_t(3), limit);
is_prime_.resize(limit/2, true);
Line 265:
* @return true if the integer is prime
*/
inline bool sieve_of_eratosthenesprime_sieve::is_prime(size_t n) const {
if (n == 2)
return true;
1,777

edits