Print the intersection of sequences Sequences

You are given four number sequences, numbered 1 through 4.


OEIS The location of 0's when the natural numbers are listed in binary. Here's an example of how to calculate the sequence:

 0,1,10,11,100,101,110,111
 ^    ^     ^^  ^    ^
 0    3     78  10   14


The start of the sequence goes like this: 0, 3, 7, 8, 10, 14, 19, 20, 21, 23, 24, 27, 29, 31, 36, 37, 40, 45, 51, ...





OEIS This sequence includes the first natural number, skips the next two, then includes the next three, then skips the next four, and continues.

 0, 3, 4, 5, 10, 11, 12, 13, 14, 21, 22, 23, 24, 25, 26, 27, 36, ...






OEIS Positive integers where both the number of 0's and the number of 1's in the binary representation of the number are powers of 2.

2, 4, 5, 6, 9, 10, 12, 16, 23, 27, 29, 30, 33, 34, 36, 39,






OEIS The Hofstadter Q sequence. 


  a(1) = a(2) = 1;
   a(n) = a(n-a(n-1)) + a(n-a(n-2)) for n > 2. 


1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 6, 8, 8, 8, 10, 9, 10, 11, 11, 12, 12, 12, 12, 16, 14, ...


Little is proven rigorously about this sequence, but many empirical results exist. One is particularly important, and you may assume it's valid for the entire series:

This paper observed that the elements of the series can be grouped into generations. If we number them starting at 1, then the kth generation contains exactly 2k elements. The relevant property is that all numbers in generation k are obtained by summing two numbers from generations k-1 and/or k-2, but never from earlier generations. You may use this (and only this) observation to put a lower bound on the remaining elements in the sequence.




Challenge

Your challenge is to print the first x numbers in the intersection of the given input sequences.

Input: Two numbers separated by a space on STDIN. The first number is an integer from 1 to 15 inclusive where each bit corresponds to a sequence. The lowest bit corresponds to sequence 1, and the highest corresponds to sequence 4. The second is amount of numbers, x, to output on STDIN.

Output: The first x numbers that intersect with the given input sequences. Print the numbers on STDOUT with any clear whitespace or punctuation as a delimiter (spaces, tabs, newlines, commas, colons, periods, etc).



Examples

1. Print the first 3 numbers that are in every sequence.

Input: 15 3

Output: 10,23,40



2. Print the first 12 numbers in sequences number 1 and 4.

Input: 9 12

Output: 3,8,10,14,19,20,21,23,24,31,37,40



3. Print the first 10 numbers in sequence 2.

Input: 2 10

Output: 0,3,4,5,10,11,12,13,14,21



4. Print the first 6 numbers in sequences 3 and 4.

Input: 12 6

Output: 2,4,5,6,9,10



Details


You may print the output as you go or all at once at the end.


Huge thanks to everyone who helped out with this in chat! This question benefited greatly from being in the sandbox.
Python 3, 590 639 characters

from itertools import count as C
D=lambda n,t='1':bin(n).count(t)
Y=range
def O():
 for n in C(0):yield from bin(n)[2:]
def B():
 s=i=0
 while 1:
  i+=s
  for j in Y(i,i+s+1):yield j
  s+=2;i+=s-1
def s(i):return D(i)==1
def F():
 a=[1]*3
 for n in C(3):a+=[a[n-a[n-1]]+a[n-a[n-2]]];yield a[-1]
L,R=input().split()
J=[x for x,U in zip([F(),(n for n in C(0)if s(D(n,'0')-1)and s(D(n))),B(),(i for i,c in enumerate(O())if'1'&gt;c)],"{0:04b}".format(int(L)))if U&gt;'0']
X=[set()for _ in J]
M=[]
Z=int(R);K=1
while len(M)&lt;Z:
 for x,j in zip(X,J):x.add(next(j))
 for _ in Y(K):X[0].add(next(J[0]));K+=1
 M=X[0]
 for x in X:M=M&amp;x
print(sorted(M)[:Z])


This is the straight-forward solution: use generators to define each of the infinite sequences, and so long as the intersection isn't large enough, add a step to each sequence.

To account for the non-monotonically-increasing Hofstadter sequence: at each step I generate twice as many for that sequence, e.g. 1, then 2, 4, 8, 16, 32, etc. I think that satisfies the bound stated in the question, and it's still fast enough for all the test cases presented there.