Strong and weak primes: Difference between revisions

m
C++ - renamed class
m (Minor edit to C++ code)
m (C++ - renamed class)
Line 309:
#include <locale>
#include <sstream>
#include "sieve_of_eratosthenesprime_sieve.hhpp"
 
int main() {
Line 318:
 
// find the prime numbers up to array_size
sieve_of_eratosthenesprime_sieve sieve(array_size);
 
// write numbers with groups of digits separated according to the system default locale
Line 356:
}</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 367:
* 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 380:
* @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 400:
* @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