LTIMindtree Interview Question

Approach of solving for prime number