Prime Visits doubt


my code is showing timelimit error in the test case no.3

hey @Ajitverma1503, constraints are high in question, please change int to long long int

still the code show TLE.

@Ajitverma1503
Since the constraints are high , you should go for an optimised approach to compute prime numbers. Try using Sieve Technique which is discussed in the Number Theory Section in your course . It is an optimised technique to precompute prime numbers and will help you resolve the TLE.

hey @gaurav13998, can you share me the updated code

hey @Ajitverma1503, as constraints are high you should use prime seive to find prime number as it takes less time.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like

https://ide.codingblocks.com/s/162325 my code is giving tle for testcase 1

@Ajitverma1503
You should call primeseive for only single time and use the same result array for each test case. This avoids calling it for every testcase.

Hope it helps
Mark the doubt if resolved :slight_smile:

thank you :smile: :+1: