Unable to handle bigger values

I am very weak in handling bigger values please let me know in details where my code is failing with comments.

You are facing TLE issue. Let’s use sieve of erasthones to get primes and get through the problem.
I have written a short code for you please have a look.