Composite Number Eliminator Class
using namespace std;
// The long long type is now standard in C, but I don't know if it's
// standard in C++. Anyway, this makes it easy to change to something
typedef unsigned long long Integer;
// Prime eliminator. It is essentially a pair of numbers, the first prime
// and the second a multiple of the first. The program keeps a collection
// of these in a heap to eliminate candidate primes.
// The base is a prime number, and the target is the next multiple
// which it has not yet eliminated.
Integer base, target;
// Create at a prime, ready to eliminate the first multiple thereof.
base = p;
target = 2*p;
// See what number is eliminated next.
// Advance to the next elimination.
target += base;
// Compare Eliminators according to their eliminated value.
bool operator<(const Eliminator &e) const
return target > e.target; // Note: Inverted sense
bool operator==(const Eliminator &e) const
return target == e.target;
cout << "(" << base << ", " << target << ")";
// This is a collection of Eliminators organized as a heap, so the next largest
// one can be found quickly.
// This holds the heap data structure.
// What does the heap eliminate just now?
// Insert a new prime eliminator into the collection.
void insert(Integer i);
// Move to the next eliminator.
// Get 'em out.