Jump to content

Strong and weak primes: Difference between revisions

m
C++ - use ostream_iterator to print list of primes
m (C++ - made function definitions out of line)
m (C++ - use ostream_iterator to print list of primes)
Line 305:
 
=={{header|C++}}==
<lang cpp>#include <iostreamalgorithm>
#include <iomanipiostream>
#include <iterator>
#include <locale>
#include <sstreamvector>
#include "prime_sieve.hpp"
 
Line 323 ⟶ 324:
int count1 = 0;
int count2 = 0;
std::ostringstreamvector<int> outprimes;
};
 
Line 330 ⟶ 331:
if (prime < limit1)
++count1;
if (count2 <= max_print) {
if primes.push_back(count2 > 1prime);
out << ' ';
out << prime;
}
}
 
void prime_info::print(std::ostream& os, const char* name) const {
os << "First " << max_print << " " << name << " primes: " << out.str() << '\n';
std::copy(primes.begin(), primes.end(), std::ostream_iterator<int>(os, " "));
outos << ' \n';
os << "Number of " << name << " primes below " << limit1 << ": " << count1 << '\n';
os << "Number of " << name << " primes below " << limit2 << ": " << count2 << '\n';
Line 425:
{{out}}
<pre>
First 36 strong primes: 11 17 29 37 41 59 67 71 79 97 101 107 127 137 149 163 179 191 197 223 227 239 251 269 277 281 307 311 331 347 367 379 397 419 431 439
Number of strong primes below 1,000,000: 37,723
Number of strong primes below 10,000,000: 320,991
First 37 weak primes: 3 7 13 19 23 31 43 47 61 73 83 89 103 109 113 131 139 151 167 181 193 199 229 233 241 271 283 293 313 317 337 349 353 359 383 389 401
Number of weak primes below 1,000,000: 37,780
Number of weak primes below 10,000,000: 321,750
1,777

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.