/*
 * Determine consecutive and triple semi-primes
 * Current ceiling is 10000: change and recompile for more
 *     cc -o consecutivesemiprimes consecutivesemiprimes.c
 * RDB, January 2013, rogerdboyle@gmail.com
 */
#define LIMIT 10000
#include <stdio.h>

int factorize();

void main(){
	int i;
	for (i=2; i<LIMIT; i++) {
		if (factorize(i)==2 && factorize(i+1)==2) {
			if (factorize(i+2)==2) {
				printf("%d %d %d\n",i,i+1,i+2);
				i++;			// Efficiency
			}
			else
				printf("%d %d\n",i,i+1);
			i++;				// Efficiency
		}
	}
}

int factorize(int n)
/*
 * Determine the prime factors of n and return their number
 * This is a very crude implementation
 */
{
  int c=0;
  int d = 2;
  
  if(n < 2)
  	return;
  while(d < n) {
    /*
     * if valid prime factor
     */
    if(n % d == 0) {
      c++;
      n /= d;
    }
    else {
      if(d == 2) d = 3;
      else d += 2;
    }
  }
  c++;			// last factor
  return(c);
}
