TLE even on sieve!

what is causing the TLE? it perfectly runs on online IDEs

def seive(m, N):
isprime = [True] * (N + 1)
primes = []
factors = [None] * (N + 1)

isprime[0] = isprime[1] = False
for i in range(2, N + 1):
    if isprime[i] == True:
        primes.append(i)
        factors[i] = i
    j = 0
    while (j < len(primes) and i * primes[j] <= N and primes[j] <= factors[i]):
        isprime[i * primes[j]] = False
        factors[i * primes[j]] = primes[j]
        j += 1

i = 0
while i < len(primes) and primes[i] <= n:
    if primes[i] >= m:
        print(primes[i], end = " ")
    i += 1

t = int(input())
for x in range(t):
m, n = [int(a) for a in input().split()]
seive(m, n)
print()

It might the case that python is slow while executing the program. Using c++ or java can solve this problem.

I’m doing the data science course so I’m meant to do this problem in python I guess. I do know how to do it in c++

Okay, you can skip this challenge as of now,
We will set a lower time bound, that can accept python codes as well…
Will inform you .
The only purpose of these challenge was to make you familiar with python :slight_smile:

Alright, thank you for answering