t=int(input())
while t > 0:
num=int(input())
lst=[]
n=0
for i in range(1,math.floor(math.sqrt(num))+1):
if num%i==0:
lst.append(i)
n=len(lst)
if n == 1:
print(1,num)
else:
print(lst[1],int(num/lst[1]))
t-=1
Question is to find two numbers within 1 to num
that multiply to become num
(for prime it is only 1, num and for rest any 2 factors). The time limit exceeded error is the thing that I am seeing now. Can anyone help me in optimizing it?
You can optimise the code by changing the limit inside the range to sqrt(num).I hope this solves your problem.
You can try like this: