p={x->(2..<x).every{x%it!=0}&x>1|x==2}f={x->(1..x).findAll({y->p(y)&'10'.every{p(Integer.toBinaryString(y).count(it))}})}[10,100,150,17].each{println f(it)}
Standard input is empty
[] [17, 19, 37, 41, 79] [17, 19, 37, 41, 79, 103, 107, 109, 131, 137] [17]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!