Doubt in Deepak and primes

In this code the two test cases are showing time limit exceeded.How to optimise?
Code

@ratulhans hey Rahul use a more optimized version of prime sieve in which you have to mark the position for prime.
there is a video of the sieve of erthothanes go through this video and you will able to optimize your code.