Again a run error

I write my codes in python and on every other problem i am running into this run error, even though the code runs fine on my system

n=int(input())
import math
def isprime(n):
    if n==2 or n==3:
        return True
    if n==1:
        return False
    i=2
    while i<=math.floor(math.sqrt(n)):
        if n%i==0:
            return False
        i+=1
    return True
count=0
i=2
while count<n:
	if isprime(i):
		count+=1
		last_prime=i
	i+=1
print (last_prime)

this code will not give run time error
it will give TLE time limit exceded

use prime seive method to pass all testcase

n=int(input()) import math def SieveOfEratosthenes(n): prime = [True for i in range(n+1)] p = 2 while(p * p <= n): # If prime[p] is not changed, then it is a prime if (prime[p] == True): # Update all multiples of p for i in range(p * p, n + 1, p): prime[i] = False p += 1 c=[] for p in range(2, n): if prime[p]: c.append§ return c # List of primes def mthPrime(m): return (SieveOfEratosthenes(100)[m-1]) print (mthPrime(n))

this was my initial attempt

i have used sieve method only

you can go through my submission

The 500,000th prime is 7,368,787.

so sizes of p array should be atleast this much
rounded off and take size of p as 7400000

i have done some optimization like

  1. traverse only on odd numbers

  2. append prime nos in c at time of making seive instead to running a loop outside

you can see the changes in modified code below

Modified Code

if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like :heart:: and don’t forgot to mark doubt as resolved :grinning:

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.