TLE in Prime Game , FEB Long challenge '21

Hi , i got 10 points for getting AC in subtask 2 , but TLE in subtask 1 and 3 , but i can’t understand why as i used Sieve of eratosthenes for Prime Factorization and i think i was within the time constraint. Can anyone help me ?
Here is my code:
t = int(input())

MAX_SIZE = 1000001
isprime = [True] * MAX_SIZE
prime = []
SPF = [None] * (MAX_SIZE)
def manipulated_seive(N):
isprime[0] = isprime[1] = False

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

manipulated_seive(1000000)

def countPrime(n):
count=0
i=0
while i<len(prime) and prime[i]<=n:
count+=1
i+=1
return count

for _ in range(t):
x,y=map(int,input().split())
if x==1:
print(‘Chef’)
elif y==1 and isprime[x]==False:
print(‘Divyam’)
elif countPrime(x)<=y:
print(“Chef”)
else:
print(‘Divyam’)

use fast input output .and find prime upto 10^6 +5.