n = int(input())
ans = n
ans = ans**0.5
a = 0
b = ans
while(a<=b):
if (aa)+(bb)==n :
print(’(’,int(a),’,’,int(b),’)’)
a = a+1
b = b+1
elif ((aa)+(bb)) > n:
b = b-1
else:
a = a+1
Problem in getting desired outputs in the code
t=int(input())
while(t):
n = int(input())
ans = n
ans = ans**0.5
a = 0
b = ans
while(a<=b):
if (a*a)+(b*b)==n :
print("(",int(a),",",int(b),")",end=" ")
a = a+1
b = b+1
elif ((a*a)+(b*b)) > n:
b = b-1
else:
a = a+1
t=t-1
print()
Your code was correct for most of the part the two main issues that your code had was that
- You didnt take into consideration you have find the solution for a multiple of test cases
- You are supposed to print all the combinations for a single number in the same line and shift to new line only for the next testcase.