Infosys interview question

Write code for prime number is optimized way?