Why it is giving TLE?
import math
t = int(input()) for _ in range(t): a, b = [int(x) for x in input().split()] l = [0 for x in range(b + 1)] for i in range(2, math.ceil(b ** 0.5) + 1): if l[i] == 0: jump = 2 while i * jump <= b: l[i * jump] = 1 jump += 1 print(*[i for i in range(max(2, a), b + 1) if l[i] == 0], sep = “\n”) print()
You are creating a list as large as the upper bound (b in your code), so your solution is O(n) with n up to 10^9. That is too long. Try looking up Segmented Sieve.