def generator(even=false, nmax=1000000)
  start = even? 2: 1
  Enumerator.new do |y|
    n = 1
    ary = [0] + (start..nmax).step(2).to_a      
    y << ary[n]
    while (m = ary[n+=1]) < ary.size
      y << m
      (m...ary.size).step(m){|i| ary[i]=nil}
      ary.compact!                              
    end
    
    ary[n..-1].each{|i| y << i}
    raise StopIteration
  end
end

def lucky(argv)
  j, k = argv[0].to_i, argv[1].to_i
  mode = /even/i=~argv[2]?:'even lucky': :lucky
  seq = generator(mode ==:'even lucky')
  ord = ->(n){}
  if k.zero?
    puts 
  elsif 0 < k
    puts ,
         
  else
    k = -k
    ary = []
    loop do
      case num=seq.next
      when 1...j
      when j..k  then ary << num
      else break
      end
    end
    puts ,
         
  end
end

if __FILE__ == $0
  lucky(ARGV)
end