Submission limit reached Python 3.x

Nooby this side.
here’s my code for calculating total cost for number of candies…The total cost is a number upto which there are n prime numbers(starting from 2).for now ignore indentation and all that stuff, problem is I’m getting submission limit maximum. Can anyone help me?


 import sys

def Prime(T,n):		 	
        for a in range(T):		    
	        ls = [2,3]
		if (n[a] < 2):
			print(2)
		else:	
			for i in range(2,n[a]):
				generate = ls[-1]+2	    
				while any(not(generate%num) for num in ls):			
					generate += 2						
				ls.append(generate)	   	    
			print(ls[-1])	
T = int(input())
n = []
for x in range(T):
	x = int(input())
	n.append(x)
Prime(T,n)

ps: sry if code’s readability is bad. I did my best to correct it

give the problem link.

Lol… But you have not anything yet… checking here https://www.codechef.com/users/jackpercy