Infosys Interview Question

Write code for prime number is optimized way?