1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
#include "primes.hpp"

using namespace hpc::gmp;

bool search_prime_constellation(
	 Integer& start_interval,
	 Integer& end_interval,
	 unsigned int k,         // size of prime constellation
	 unsigned int offsets[], // k-1 offsets
	 Integer& first_prime) {   // found result (if returning true)
   Integer p = start_interval;
   Integer q;
   bool found = false;
   for(;;) {
      // lookout for the next prime in the interval
      mpz_nextprime(p.get_mpz_t(), p.get_mpz_t());
      if (p > end_interval) break;
      // p is apparently prime, check for an constellation
      found = true;
      for (unsigned int i = 0; i < k-1; ++i) {
	 unsigned int offset = offsets[i];
	 q = p + offset;
	 if (mpz_probab_prime_p(q.get_mpz_t(), 10) < 1) {
	    found = false;
	    break; // not a prime
	 }
      }
      if (found) break;
   }
   if (found) {
      first_prime = p;
   }
   return found;
}