Second attempt with a segmented sieve with segment size 210: 76 seconds. It can still be improved significantly, as I haven't done any wheel sieving yet.
EDIT: 69 seconds.
EDIT 2: 57 seconds.
EDIT 3: Now 54 seconds.
Code: startTmr->T
Repeat checkTmr(T:End
7907->N
210->B //segment size
//first, make a list L3 of all 48 mod-210 residues of primes
//they go from A+11 to A+211
//for all of them to be at most N
//this takes 2 seconds
0->dim(L3
For([recursiven],1,B,2:
If min(remainder([recursiven],{3,5,7
[recursiven]->L3(1+dim(L3
End
Disp checkTmr(T
//now make a list L4 of small primes, less than sqrt(N). Don't include 2, 3, 5, 7.
//takes 1 more second
{11,13->L4
For([recursiven],13,sqrt(N),2:
If min(remainder([recursiven],{3,5,7,11,13
[recursiven]->L4(1+dim(L4
End
//now make a list of their starting points, i.e. their squares
//time is negligible
max(L4+210,L4^^2->L5
11*21->L5(1
13*17->L5(2
Disp checkTmr(T
//finally, make a list L2 to sieve on
//list goes from A+2 to A+B+1
B->dim(L2
augment({2,3,5,7},L4->L1 //L1 is all primes
//fill out the first bucket, from 11 to 211
For([recursiven],[recursiven],B,2:
If min(remainder([recursiven],{3,5,7,11,13
[recursiven]->L1(1+dim(L1
End
Disp checkTmr(T
For(A,B,N-B,B //for each bucket, but not the first or last
Disp A //bucket goes from A+1 to A+B
Fill(1,L2
For(I,1,dim(L4
For([recursiven],L5(I)-A,B,2L4(I //zero all multiples
0->L2([recursiven]
End
[recursiven]+A->L5(I
End
Disp 1
For([recursiven],1,dim(L3:
If L2(L3([recursiven]
A+L3([recursiven]->L1(1+dim(L1
End
End
//finally, finish up the last bucket
Disp A //bucket goes from A+1 to A+B
Fill(1,L2
For(I,1,dim(L4
For([recursiven],L5(I)-A,B,2L4(I //zero all multiples
0->L2([recursiven]
End
[recursiven]+A->L5(I
End
Disp 1
For([recursiven],1,sum(not(cumSum(L3+A>N:
If L2(L3([recursiven]
A+L3([recursiven]->L1(1+dim(L1
End
Disp checkTmr(T
1/(sum(L1)=3674994)
EDIT 4: My program is now about the same speed as jonbush's: 43s on jsTIfied 2.55MP. I didn't account for differences in calculator speed.
Code: startTmr->T
Repeat checkTmr(T:End
7907->N
210->B //segment size
//first, make a list L3 of all 48 mod-210 residues of primes
//they go from A+11 to A+211
//for all of them to be at most N
//this takes 2 seconds
0->dim(L3
For([recursiven],1,B,2:
If min(remainder([recursiven],{3,5,7
[recursiven]->L3(1+dim(L3
End
Disp checkTmr(T
//now make a list L4 of small primes, less than sqrt(N). Don't include 2, 3, 5, 7.
//takes 1 more second
{11,13->L4
For([recursiven],13,sqrt(N),2:
If min(remainder([recursiven],{3,5,7,11,13
[recursiven]->L4(1+dim(L4
End
//now make a list of their starting points, i.e. their squares
//time is negligible
max(L4+210,L4^^2->L5
11*21->L5(1
13*17->L5(2
Disp checkTmr(T
//finally, make a list L2 to sieve on
//list goes from A+2 to A+B+1
B->dim(L2
augment({2,3,5,7},L4->L1 //L1 is all primes
//fill out the first bucket, from 11 to 211
For([recursiven],[recursiven],B,2:
If min(remainder([recursiven],{3,5,7,11,13
[recursiven]->L1(1+dim(L1
End
Disp checkTmr(T
For(A,B,N-B,B //for each bucket, but not the first or last
//Disp A //bucket goes from A+1 to A+B
Fill(1,L2
L5-B->L5
For(I,1,dim(L4
For([recursiven],L5(I),B,2L4(I //zero all multiples
0->L2([recursiven]
End
[recursiven]->L5(I
End
//Disp 1
For([recursiven],1,dim(L3:
If L2(L3([recursiven]
A+L3([recursiven]->L1(1+dim(L1
End
End
//finally, finish up the last bucket
//Disp A //bucket goes from A+1 to A+B
Fill(1,L2
L5-B->L5
For(I,1,dim(L4
For([recursiven],L5(I),B,2L4(I //zero all multiples
0->L2([recursiven]
End
End
//Disp 1
For([recursiven],1,sum(L3+A<=N:
If L2(L3([recursiven]
A+L3([recursiven]->L1(1+dim(L1
End
Disp checkTmr(T
1/(sum(L1)=3674994)
It may be considered cheating that I've hardcoded the primes up to 13, but if that's an issue it can be easily fixed.
EDIT 5: 42s by pre-doubling L4 and by replacing A and B with finance variables. I don't know how else I can optimize it. Bucket size 420 speeds up the algorithm by 3s, but it also slows down the first bucket by 3s, so it breaks even.
The code is pretty big too: 507 bytes. It's a long way to earthnite's 29s—the part of mine that stores the already-identified primes into L1 is almost that slow by itself.