HELP NEEDED
import math
import bisect
import collections
from collections import defaultdict, Counter
inf = float(‘inf’)
mod = 10**9 + 7
t = int(input())
maxn = 10**6 + 1
for _ in range(t):
k = int(input())
if k % 2 == 0:
print(k * 2)
continue
def sieve(num):
prime = [True for i in range(num + 1)]
# spf = [i for i in range(num + 1)]
prime[0] = prime[1] = False
for p in range(2, int(num**0.5) + 1):
if prime[p]:
for i in range(p * p, num + 1, p):
prime[i] = False
# if spf[i] == i:
# spf[i] = p
# return prime, spf
return prime
def smallest(k):
for i in range(2, int(k**0.5)+1):
if k % i == 0:
return i
return k
# prime, spf = sieve(maxn)
prime= sieve(maxn)
s = 0
x = smallest(k)
primevals = []
presum = []
for i in range(len(prime)):
if prime[i]:
s += i
presum.append(s)
print(k * presum[x])
hi can anyone explain why my code is facing tle issues i have tried over dozen submissions trying to optimize here and there but it hasnt got accepted. Please help!!!