res = [] for i in range(1,2+1,10): res.append([]) for j in range(i, i+10): if j**2 % k != 0: res[-1].append(j**2)