Strong and weak primes: Difference between revisions
Content added Content deleted
m (Minor edit to C++ code) |
m (Reformatted to reduce line count) |
||
Line 311: | Line 311: | ||
#include "sieve_of_eratosthenes.h" |
#include "sieve_of_eratosthenes.h" |
||
int main() |
int main() { |
||
{ |
|||
const int limit1 = 1000000; |
const int limit1 = 1000000; |
||
const int limit2 = 10000000; |
const int limit2 = 10000000; |
||
Line 331: | Line 330: | ||
const char* strength[2] = { "strong", "weak" }; |
const char* strength[2] = { "strong", "weak" }; |
||
int p1 = 2, p2 = 3; |
int p1 = 2, p2 = 3; |
||
for (int p3 = 5; p2 < limit2; ++p3) |
for (int p3 = 5; p2 < limit2; ++p3) { |
||
{ |
|||
if (!sieve.is_prime(p3)) |
if (!sieve.is_prime(p3)) |
||
continue; |
continue; |
||
int diff = p1 + p3 - 2 * p2; |
int diff = p1 + p3 - 2 * p2; |
||
int index = diff < 0 ? 0 : (diff > 0 ? 1 : -1); |
int index = diff < 0 ? 0 : (diff > 0 ? 1 : -1); |
||
if (index != -1) |
if (index != -1) { |
||
{ |
|||
++count2[index]; |
++count2[index]; |
||
if (p2 < limit1) |
if (p2 < limit1) |
||
++count1[index]; |
++count1[index]; |
||
if (count2[index] <= max_print[index]) |
if (count2[index] <= max_print[index]) { |
||
{ |
|||
if (count2[index] > 1) |
if (count2[index] > 1) |
||
out[index] << ' '; |
out[index] << ' '; |
||
Line 352: | Line 348: | ||
p2 = p3; |
p2 = p3; |
||
} |
} |
||
for (int i = 0; i < 2; ++i) |
for (int i = 0; i < 2; ++i) { |
||
{ |
|||
std::cout << "First " << max_print[i] << " " << strength[i] << " primes: " << out[i].str() << '\n'; |
std::cout << "First " << max_print[i] << " " << strength[i] << " primes: " << out[i].str() << '\n'; |
||
std::cout << "Number of " << strength[i] << " primes below " << limit1 << ": " << count1[i] << '\n'; |
std::cout << "Number of " << strength[i] << " primes below " << limit1 << ": " << count1[i] << '\n'; |