enum {
	NPRIMES = 100*1000
};

#include <stdio.h>
#include <stdint.h>
#include <math.h>

uint32_t typedef word;

enum {
	B = sizeof(word) * 8,
	NP = NPRIMES + B - 1 & -B,
	NW = NP / B 
};

word si[NW] = {3};

int main()
{
	int unsigned i, j, k, t;
	word w, v, *p, *q;

	for(i = 0; i < B-1; i++){
		if((0[si] & 1<<i) != 0)
			continue;
		v = w = 1;
		while(w != 0)
			v |= w <<= i;
		j = B % i;
		p = si;
		*p++ |= v & -(1 << i+1); 
		for(; p < si + NW; p++)
			*p |= v = v >> j | v << i - j;
	}
	t = ceil(sqrt(NP));
	for(p = si, i = 0; p < si + NW; p++){
		union { double d; uint64_t f;};
		w = *p;
		while(w != (unsigned)-1){
			v = ~w & w+1;
			d = v + 0.0125;
			k = i + (f >> 52) - 1023;
			printf("%d\n", k);
			if(k >= B-1 && k < t)
				for(q = si, j = k << 1; (q += j/B) < si + NW; j += k)
					*q |= 1 << (j &= B - 1);
			w |= v;
		}
		i += B;
	}
	return 0;
}
