PRETNUM problem-why am i getting time limit exceeded error?

link textalt text
This is the link to my code. The space used is 2340KB and time taken is 1.01 secs. how can i reduce memory usage? I have tried using recursions but in vain. Kindly help.

memory is not the issue, your method is timing out

can you please explain why wont this method work?

Maybe because counting number of factors of each ans every number between [L,R] and then checking it to be prime where R-L can be as large as 10^6 will time out.
refer to editorials