Prime Visits timelimit problem

There is a timelimit error for testcase 3. Code is in the comments.

84067 is the id for my code on coding blocks ide.

Plz use prime seive optimisation in your code as given in online video lectures.

I am having the same problem

Plz refer to the video given in online lecture for better understanding