Prime Visits, Simple Array question. Course Algo++

https://online.codingblocks.com/player/34497/content/13211/4712

The third test case in the given problem gives me tle.
how optimise this solution.

@A17CRX0055 hey dhananjay their is method of sieve of eratosthenes using that you can optmise it further.