def powers(m)
  return enum_for(__method__, m) unless block_given?
  0.step{|n| yield n**m}
end

def squares_without_cubes
  return enum_for(__method__) unless block_given?

  cubes = powers(3)
  c = cubes.next
  powers(2) do |s|
    c = cubes.next while c < s
    yield s unless c == s
  end
end

p squares_without_cubes.take(30).drop(20)