Back to General discussions forum
def pytr(n):
for i in range(1, int(n/3)+1):
for j in range(i+1, int(n/2)+1):
k=n-i-j
if (i*i + j*j == k*k):
return [i,j,k]
a=int(input())
l=[]
for i in range(a):
b=int(input())
c=pytr(b)
l.append(c[2]**2)
[print(x,end=' ') for x in l]
Getting answer for small input but for large inputs time limit exceed.
Hi! Your approach is good for small numbers but for larger it could be not quite efficient.
Note it has nested loop about N
size, thus about N*N
operations - e.g. time consumption grows fast.
So you are expected to find some better, probably somewhat math-related approach.
However feel free to set this problem aside for some time and return to it later. Good luck!